好的,所以我一直在谷歌上搜索,一无所获。 如何获取Auth :: user()对象,然后获取具有数据透视表的该用户的所有帐户,然后获取子项目说明作业。 如此。
//gets me the user object
$user = Auth::user();
//pivot table account_user
//gets me all the users accounts
$accounts = $user->account()->get();
//this gets me all the accounts with the 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();
}
所以我想要用户拥有的所有帐户以及每个帐户我想要的job_id他们已经用外来列名替换了,或者能够从它生成的json对象中获取它。
答案 0 :(得分:0)
要执行此操作,您需要在帐户模型上使用with,如此。 $ accounts = $ user-> account() - > with(' Financialinstitution') - > get();