Mercurial > packages > magicforger
annotate src/Generator/Model/stubs/model.stub @ 29:010ace248d14 codex
Added support for filters, not fully there with relations or anything like that but it's a start
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Mon, 09 Jun 2025 20:51:04 -0400 |
| parents | f88d2d5dee30 |
| children | 8dd668020310 |
| rev | line source |
|---|---|
| 4 | 1 <?php |
| 2 | |
| 3 namespace {{ namespace }}; | |
| 4 | |
| 5 | 5 use Illuminate\Database\Eloquent\SoftDeletes; |
| 4 | 6 |
|
29
010ace248d14
Added support for filters, not fully there with relations or anything like that but it's a start
Luka Sitas <sitas.luka.97@gmail.com>
parents:
28
diff
changeset
|
7 class {{ class }} extends BaseModel |
| 4 | 8 { |
| 5 | 9 //use HasFactory; |
| 10 use SoftDeletes; | |
| 11 | |
| 12 /** | |
| 13 * The table associated with the model. | |
| 14 * | |
| 15 * @var string | |
| 16 */ | |
| 17 protected $table = '{{ tableName }}'; | |
| 18 | |
| 19 /** | |
| 20 * The model's default values for attributes. | |
| 21 * | |
| 22 * @var array | |
| 23 */ | |
| 24 protected $attributes = [ | |
| 25 # {{ atributeInsertPoint }} | |
| 26 ]; | |
| 27 | |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
28 protected $fillable = [ |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
29 # {{ fillableInsertPoint }} |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
30 ]; |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
31 |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
32 protected $default_relations = [ |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
33 # {{ defaultRelationsInsertPoint }} |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
34 ]; |
| 5 | 35 |
|
29
010ace248d14
Added support for filters, not fully there with relations or anything like that but it's a start
Luka Sitas <sitas.luka.97@gmail.com>
parents:
28
diff
changeset
|
36 protected static $filters = [ |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
37 # {{ defaultFiltersInsertPoint }} |
|
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
38 ]; |
| 5 | 39 |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
40 public static function get_filters() { |
|
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
41 return static::filters; |
| 5 | 42 } |
| 11 | 43 |
| 44 //relations | |
| 45 | |
| 46 // BelongsTo | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
47 # {{ belongs_to_relationships }} |
| 11 | 48 |
| 49 // HasMany | |
|
24
31109c61ce02
Refactor RelationshipNavigator formatting and implement belongsTo, hasMany, belongsToMany injection in ModelGenerator
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
50 # {{ has_many_relationships }} |
| 11 | 51 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
52 // HasManyThrough |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
53 # {{ has_many_through_relationships }} |
| 11 | 54 |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
55 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
56 /** |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
57 * Load the default relations for the model. |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
58 * |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
59 * @return $this |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
60 */ |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
61 public function load_relations() { |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
62 foreach($this->default_relations as $relation) { |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
63 $this->load($relation); |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
64 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
65 return $this; |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
66 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
67 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
68 /** |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
69 * Retrieve a query builder instance with default relations loaded. |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
70 * |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
71 * @return \Illuminate\Database\Eloquent\Builder |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
72 */ |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
73 public static function data_query() { |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
74 return parent::data_query(); |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
75 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
76 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
77 /** |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
78 * Retrieve a query builder instance with default relations loaded. |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
79 * |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
80 * @return \Illuminate\Database\Eloquent\Builder |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
81 */ |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
82 public static function get_data(array $validated = []) |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
83 { |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
84 return parent::get_data($validated); |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
85 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
86 |
| 4 | 87 } |
