Laravel Model accessing a value of an instance of its self -
i've got model , model self linked multiple other databases 1 @ time.
instead of having eloquent method possible databases; have 1 use variable self instance choose database , return that.
it save alot of work, returning each 1 , testing see if there results cumbersome.
<?php namespace app; use illuminate\database\eloquent\model; class feature extends model { /** * database table used model. * * @var string */ protected $table = 'companies'; /** * attributes mass assignable. * * @var array */ protected $fillable = [ 'name', ]; /** * attributes excluded model's json form. * * @var array */ protected $hidden = [ 'db_name', 'enabled', ]; /** * uses own database name determine input return. */ public function inputs() { // if this->hidden->db_name == 'input type 1' // return $this->hasmany(inputtype1::class); .... , on } // end function inputs }
this strange behaviour think can achieve looking :
//in model public function inputs() { switch ($this->attributes['db_name']) { case : 'input type 1': return $this->hasmany(inputtype1::class); case : //some other database name return //another relation } }
Comments
Post a Comment