Mercurial > packages > magicforger
comparison src/Generator/Model/stubs/model.stub @ 34:f65ab84ee47f default
merge with codex
| author | luka |
|---|---|
| date | Wed, 10 Sep 2025 21:00:47 -0400 |
| parents | 8dd668020310 |
| children | 76584181267a |
comparison
equal
deleted
inserted
replaced
| 10:a9ff874afdbd | 34:f65ab84ee47f |
|---|---|
| 1 <?php | 1 <?php |
| 2 | 2 |
| 3 namespace {{ namespace }}; | 3 namespace {{ namespace }}; |
| 4 | 4 |
| 5 use Illuminate\Database\Eloquent\Factories\HasFactory; | |
| 6 use Illuminate\Database\Eloquent\Model; | |
| 7 use Illuminate\Database\Eloquent\SoftDeletes; | 5 use Illuminate\Database\Eloquent\SoftDeletes; |
| 6 use Wizard\Framework\Models\BaseModel; | |
| 8 | 7 |
| 9 class {{ class }} extends Model | 8 class {{ class }} extends BaseModel |
| 10 { | 9 { |
| 11 //use HasFactory; | 10 //use HasFactory; |
| 12 use SoftDeletes; | 11 use SoftDeletes; |
| 13 | 12 |
| 14 /** | 13 /** |
| 25 */ | 24 */ |
| 26 protected $attributes = [ | 25 protected $attributes = [ |
| 27 # {{ atributeInsertPoint }} | 26 # {{ atributeInsertPoint }} |
| 28 ]; | 27 ]; |
| 29 | 28 |
| 29 protected $casts = [ | |
| 30 # {{ castInsertPoint }} | |
| 31 ]; | |
| 30 | 32 |
| 31 public static function boot() : void { | 33 protected $fillable = [ |
| 32 parent::boot(); | 34 # {{ fillableInsertPoint }} |
| 35 ]; | |
| 33 | 36 |
| 34 self::creating(function ($item) { | 37 protected $default_relations = [ |
| 35 $item->created_by = \Auth::user()->id; | 38 # {{ defaultRelationsInsertPoint }} |
| 36 $item->updated_by = \Auth::user()->id; | 39 ]; |
| 37 }); | |
| 38 | 40 |
| 39 self::saving(function ($item) { | 41 protected static $filters = [ |
| 40 $item->updated_by = \Auth::user()->id; | 42 # {{ defaultFiltersInsertPoint }} |
| 41 }); | 43 ]; |
| 44 | |
| 45 public static function get_filters() { | |
| 46 return static::filters; | |
| 42 } | 47 } |
| 48 | |
| 49 //relations | |
| 50 | |
| 51 // BelongsTo | |
| 52 # {{ belongs_to_relationships }} | |
| 53 | |
| 54 // HasMany | |
| 55 # {{ has_many_relationships }} | |
| 56 | |
| 57 // HasManyThrough | |
| 58 # {{ has_many_through_relationships }} | |
| 59 | |
| 60 | |
| 61 /** | |
| 62 * Load the default relations for the model. | |
| 63 * | |
| 64 * @return $this | |
| 65 */ | |
| 66 public function load_relations() { | |
| 67 foreach($this->default_relations as $relation) { | |
| 68 $this->load($relation); | |
| 69 } | |
| 70 return $this; | |
| 71 } | |
| 72 | |
| 73 /** | |
| 74 * Retrieve a query builder instance with default relations loaded. | |
| 75 * | |
| 76 * @return \Illuminate\Database\Eloquent\Builder | |
| 77 */ | |
| 78 public static function data_query() { | |
| 79 return parent::data_query(); | |
| 80 } | |
| 81 | |
| 82 /** | |
| 83 * Retrieve a query builder instance with default relations loaded. | |
| 84 * | |
| 85 * @return \Illuminate\Database\Eloquent\Builder | |
| 86 */ | |
| 87 public static function get_data(array $validated = []) | |
| 88 { | |
| 89 return parent::get_data($validated); | |
| 90 } | |
| 91 | |
| 43 } | 92 } |
