Mercurial > packages > magicforger
diff src/Generator/Model/stubs/model.pivot.stub @ 34:f65ab84ee47f default
merge with codex
| author | luka |
|---|---|
| date | Wed, 10 Sep 2025 21:00:47 -0400 |
| parents | b17f81b804ff |
| children |
line wrap: on
line diff
--- a/src/Generator/Model/stubs/model.pivot.stub Sat Dec 02 10:20:32 2023 -0500 +++ b/src/Generator/Model/stubs/model.pivot.stub Wed Sep 10 21:00:47 2025 -0400 @@ -10,12 +10,96 @@ /** * Indicates if the model should be timestamped. - * By default our pivots will not use timestamps + * By default our pivots will not use timestamps * * @var bool */ public $timestamps = false; + protected $default_relations = [ + # {{ defaultRelationsInsertPoint }} + ]; + //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; + } + + //MARK FOR MODEL + public static function load_index() { + return static::load_auxilary_data(); + } + + //MARK FOR MODEL + public static function load_create() { + return static::load_auxilary_data(); + } + + //MARK FOR MODEL + public static function load_edit() { + return static::load_auxilary_data(); + } + + + /** + * Retrieve a query builder instance with default relations loaded. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + //MARK FOR MODEL + public static function data_query() { + $query = static::query(); + + $instance = new static(); + + foreach($instance->default_relations as $relation) { + $query->with($relation); + } + + return $query; + } + + /** + * Retrieve a query builder instance with default relations loaded. + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function get_data() + { + return static::data_query()->get(); + } }
