Mercurial > packages > magicforger
view src/Generator/Model/stubs/model.stub @ 28:f88d2d5dee30 codex
Updated inputs and routes
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Mon, 09 Jun 2025 19:51:31 -0400 |
| parents | 555bfaa500ac |
| children | 010ace248d14 |
line wrap: on
line source
<?php namespace {{ namespace }}; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class {{ class }} extends Model { //use HasFactory; use SoftDeletes; /** * The table associated with the model. * * @var string */ protected $table = '{{ tableName }}'; /** * The model's default values for attributes. * * @var array */ protected $attributes = [ # {{ atributeInsertPoint }} ]; protected $fillable = [ # {{ fillableInsertPoint }} ]; protected $default_relations = [ # {{ defaultRelationsInsertPoint }} ]; protecte static $filters = [ # {{ defaultFiltersInsertPoint }} ]; public static function get_filters() { return static::filters; } //relations // BelongsTo # {{ belongs_to_relationships }} // HasMany # {{ has_many_relationships }} // HasManyThrough # {{ has_many_through_relationships }} /** * Load the default relations for the model. * * @return $this */ public function load_relations() { foreach($this->default_relations as $relation) { $this->load($relation); } return $this; } //MARK FOR MODEL protected static function load_auxilary_data() { $data = []; $instance = new static(); foreach($instance->default_relations as $relation) { $related_model = $instance->$relation()->getRelated(); $related_table = $related_model->getTable(); $data[$related_table] = $related_model->all()->pluck('name','id')->toArray(); } return $data; } /** * Retrieve a query builder instance with default relations loaded. * * @return \Illuminate\Database\Eloquent\Builder */ public static function data_query() { return parent::data_query(); } /** * Retrieve a query builder instance with default relations loaded. * * @return \Illuminate\Database\Eloquent\Builder */ public static function get_data(array $validated = []) { return parent::get_data($validated); } }
