annotate src/Generator/Model/stubs/model.stub @ 26:555bfaa500ac codex

Big update for view creation based on the column type.
author Luka Sitas <sitas.luka.97@gmail.com>
date Thu, 15 May 2025 21:50:38 -0400
parents 31109c61ce02
children f88d2d5dee30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
1 <?php
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
2
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
3 namespace {{ namespace }};
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
5 use Illuminate\Database\Eloquent\Factories\HasFactory;
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
6 use Illuminate\Database\Eloquent\Model;
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
7 use Illuminate\Database\Eloquent\SoftDeletes;
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
8
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
9 class {{ class }} extends Model
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
10 {
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
11 //use HasFactory;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
12 use SoftDeletes;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
13
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
14 /**
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
15 * The table associated with the model.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
16 *
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
17 * @var string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
18 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
19 protected $table = '{{ tableName }}';
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
20
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
21 /**
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
22 * The model's default values for attributes.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
23 *
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
24 * @var array
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
25 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
26 protected $attributes = [
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
27 # {{ atributeInsertPoint }}
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
28 ];
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
29
26
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
30 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
31 # {{ fillableInsertPoint }}
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
32 ];
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
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 $default_relations = [
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
35 # {{ defaultRelationsInsertPoint }}
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
36 ];
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
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 //MARK FOR MODEL
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
39 public static function boot() : void {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
40 parent::boot();
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
41
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
42 self::creating(function ($item) {
26
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
43 $item->created_by = \Auth::user()?->id ?? '';
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
44 $item->updated_by = \Auth::user()?->id ?? '';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
45 });
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
46
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
47 self::saving(function ($item) {
26
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
48 $item->updated_by = \Auth::user()?->id ?? '';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
49 });
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
50 }
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
51
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
52
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
53 //relations
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
54
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
55 // BelongsTo
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
56 # {{ belongs_to_relationships }}
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
57
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
58 // 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
59 # {{ has_many_relationships }}
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
60
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
61 // HasManyThrough
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 11
diff changeset
62 # {{ has_many_through_relationships }}
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 5
diff changeset
63
26
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 /**
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
66 * 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
67 *
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
68 * @return $this
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
69 */
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
70 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
71 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
72 $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
73 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
74 return $this;
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 //MARK FOR MODEL
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
78 protected static function load_auxilary_data() {
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
79 $data = [];
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
80
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
81 $instance = new static();
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 foreach($instance->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
84 $related_model = $instance->$relation()->getRelated();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
85 $related_table = $related_model->getTable();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
86 $data[$related_table] = $related_model->all()->pluck('name','id')->toArray();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
87 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
88
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
89 return $data;
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
90 }
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 //MARK FOR MODEL
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
93 public static function load_index() {
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
94 return static::load_auxilary_data();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
95 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
96
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
97 //MARK FOR MODEL
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
98 public static function load_create() {
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
99 return static::load_auxilary_data();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
100 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
101
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
102 //MARK FOR MODEL
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
103 public static function load_edit() {
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
104 return static::load_auxilary_data();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
105 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
106
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
107
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
108 /**
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
109 * 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
110 *
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
111 * @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
112 */
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
113 //MARK FOR MODEL
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
114 public static function data_query() {
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
115 $query = static::query();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
116
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
117 $instance = new static();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
118
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
119 foreach($instance->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
120 $query->with($relation);
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
121 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
122
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
123 return $query;
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
124 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
125
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
126 /**
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
127 * 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
128 *
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
129 * @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
130 */
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
131 public static function get_data()
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
132 {
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
133 return static::data_query()->get();
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
134 }
555bfaa500ac Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents: 24
diff changeset
135
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents:
diff changeset
136 }