我希望在执行此操作时插入枢轴:
App\User::find(1)->roles()->save($role, ['expires' => $expires]);
在模型中:
public function roles()
{
return $this->belongsToMany('App\Role');
}
我希望能够做到这一点:
$pivot = App\User::find(1)->roles()->save($role, ['expires' => $expires]);
答案 0 :(得分:1)
在您的模型中,您应该在方法关系中添加withPivot
public function roles()
{
return $this->belongsToMany('App\Role')->withPivot('expires', 'column2');
}
之后你可以这样称呼它:
$user = App\User::find(1)->roles()->save($role, ['expires' => $expires]);
$pivot = $user->pivot-> expires;