laravel - Get foreign key column with a pivot table in between the first two arguments of a user I.E. Auth::user()->account->job -
ok have been googling lot , found nothing. how take auth::user() object accounts user pivot sub item jobs. so.
//gets me user object $user = auth::user(); //pivot table account_user //gets me users accounts $accounts = $user->account()->get(); //this gets me accounts correct jobs $accounts = account::with('job')->get(); class account extends model{ public function user() {return $this->belongstomany('app\user')->withpivot('a','b','c','d')->withtimestamps();} public function job(){return $this->belongsto('app\job');} } class user extends model implements authenticatablecontract,authorizablecontract,canresetpasswordcontract{ public function account(){return $this->belongstomany('app\account')->withpivot('a','b','c','d')->withtimestamps(); }
so wanting accounts user has , on each of them want job_id have replaced foreign column name or able json object makes.
to need use on accounts model so. $accounts = $user->account()->with('financialinstitution')->get();
Comments
Post a Comment