Mercurial > packages > magicforger
annotate src/Generator/Model/stubs/model.stub @ 36:76584181267a ls_dev_2025_09
Got factories working in a basic way, not sure how complex tables will handle it though
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Sat, 20 Sep 2025 17:14:29 -0400 |
| parents | 8dd668020310 |
| children | 2cf26b593f4a |
| rev | line source |
|---|---|
| 4 | 1 <?php |
| 2 | |
| 3 namespace {{ namespace }}; | |
| 4 | |
| 5 | 5 use Illuminate\Database\Eloquent\SoftDeletes; |
|
31
8dd668020310
started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
6 use Wizard\Framework\Models\BaseModel; |
| 4 | 7 |
|
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
|
8 class {{ class }} extends BaseModel |
| 4 | 9 { |
|
36
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
31
diff
changeset
|
10 /** @use HasFactory<\Database\Factories\{{ class }}Factory> */ |
| 5 | 11 //use HasFactory; |
| 12 use SoftDeletes; | |
| 13 | |
| 14 /** | |
| 15 * The table associated with the model. | |
| 16 * | |
| 17 * @var string | |
| 18 */ | |
| 19 protected $table = '{{ tableName }}'; | |
| 20 | |
| 21 /** | |
| 22 * The model's default values for attributes. | |
| 23 * | |
| 24 * @var array | |
| 25 */ | |
| 26 protected $attributes = [ | |
| 27 # {{ atributeInsertPoint }} | |
| 28 ]; | |
| 29 | |
|
31
8dd668020310
started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
30 protected $casts = [ |
|
8dd668020310
started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
31 # {{ castInsertPoint }} |
|
8dd668020310
started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
32 ]; |
|
8dd668020310
started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents:
29
diff
changeset
|
33 |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
34 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
|
35 # {{ fillableInsertPoint }} |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
36 ]; |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
37 |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
38 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
|
39 # {{ defaultRelationsInsertPoint }} |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
40 ]; |
| 5 | 41 |
|
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
|
42 protected static $filters = [ |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
43 # {{ defaultFiltersInsertPoint }} |
|
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
44 ]; |
| 5 | 45 |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
46 public static function get_filters() { |
|
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
47 return static::filters; |
| 5 | 48 } |
| 11 | 49 |
| 50 //relations | |
| 51 | |
| 52 // BelongsTo | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
53 # {{ belongs_to_relationships }} |
| 11 | 54 |
| 55 // 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
|
56 # {{ has_many_relationships }} |
| 11 | 57 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
58 // HasManyThrough |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
11
diff
changeset
|
59 # {{ has_many_through_relationships }} |
| 11 | 60 |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
61 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
62 /** |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
63 * 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
|
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 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
|
68 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
|
69 $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
|
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 $this; |
|
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 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
74 /** |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
75 * 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
|
76 * |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
77 * @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
|
78 */ |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
79 public static function data_query() { |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
80 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
|
81 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
82 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
83 /** |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
84 * 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
|
85 * |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
86 * @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
|
87 */ |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
88 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
|
89 { |
|
28
f88d2d5dee30
Updated inputs and routes
Luka Sitas <sitas.luka.97@gmail.com>
parents:
26
diff
changeset
|
90 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
|
91 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
24
diff
changeset
|
92 |
| 4 | 93 } |
