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