Mercurial > packages > magicforger
comparison src/Generator/Model/stubs/model.stub @ 28:f88d2d5dee30 codex
Updated inputs and routes
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Mon, 09 Jun 2025 19:51:31 -0400 |
| parents | 555bfaa500ac |
| children | 010ace248d14 |
comparison
equal
deleted
inserted
replaced
| 27:b17f81b804ff | 28:f88d2d5dee30 |
|---|---|
| 33 | 33 |
| 34 protected $default_relations = [ | 34 protected $default_relations = [ |
| 35 # {{ defaultRelationsInsertPoint }} | 35 # {{ defaultRelationsInsertPoint }} |
| 36 ]; | 36 ]; |
| 37 | 37 |
| 38 //MARK FOR MODEL | 38 protecte static $filters = [ |
| 39 public static function boot() : void { | 39 # {{ defaultFiltersInsertPoint }} |
| 40 parent::boot(); | 40 ]; |
| 41 | 41 |
| 42 self::creating(function ($item) { | 42 public static function get_filters() { |
| 43 $item->created_by = \Auth::user()?->id ?? ''; | 43 return static::filters; |
| 44 $item->updated_by = \Auth::user()?->id ?? ''; | |
| 45 }); | |
| 46 | |
| 47 self::saving(function ($item) { | |
| 48 $item->updated_by = \Auth::user()?->id ?? ''; | |
| 49 }); | |
| 50 } | 44 } |
| 51 | |
| 52 | 45 |
| 53 //relations | 46 //relations |
| 54 | 47 |
| 55 // BelongsTo | 48 // BelongsTo |
| 56 # {{ belongs_to_relationships }} | 49 # {{ belongs_to_relationships }} |
| 87 } | 80 } |
| 88 | 81 |
| 89 return $data; | 82 return $data; |
| 90 } | 83 } |
| 91 | 84 |
| 92 //MARK FOR MODEL | |
| 93 public static function load_index() { | |
| 94 return static::load_auxilary_data(); | |
| 95 } | |
| 96 | |
| 97 //MARK FOR MODEL | |
| 98 public static function load_create() { | |
| 99 return static::load_auxilary_data(); | |
| 100 } | |
| 101 | |
| 102 //MARK FOR MODEL | |
| 103 public static function load_edit() { | |
| 104 return static::load_auxilary_data(); | |
| 105 } | |
| 106 | |
| 107 | 85 |
| 108 /** | 86 /** |
| 109 * Retrieve a query builder instance with default relations loaded. | 87 * Retrieve a query builder instance with default relations loaded. |
| 110 * | 88 * |
| 111 * @return \Illuminate\Database\Eloquent\Builder | 89 * @return \Illuminate\Database\Eloquent\Builder |
| 112 */ | 90 */ |
| 113 //MARK FOR MODEL | |
| 114 public static function data_query() { | 91 public static function data_query() { |
| 115 $query = static::query(); | 92 return parent::data_query(); |
| 116 | |
| 117 $instance = new static(); | |
| 118 | |
| 119 foreach($instance->default_relations as $relation) { | |
| 120 $query->with($relation); | |
| 121 } | |
| 122 | |
| 123 return $query; | |
| 124 } | 93 } |
| 125 | 94 |
| 126 /** | 95 /** |
| 127 * Retrieve a query builder instance with default relations loaded. | 96 * Retrieve a query builder instance with default relations loaded. |
| 128 * | 97 * |
| 129 * @return \Illuminate\Database\Eloquent\Builder | 98 * @return \Illuminate\Database\Eloquent\Builder |
| 130 */ | 99 */ |
| 131 public static function get_data() | 100 public static function get_data(array $validated = []) |
| 132 { | 101 { |
| 133 return static::data_query()->get(); | 102 return parent::get_data($validated); |
| 134 } | 103 } |
| 135 | 104 |
| 136 } | 105 } |
