phpclass User extends Model {
public function role()
{
return $this->hasOne('App\Role','user_id', 'id');
}
}
class Role extends Model {
public function permission()
{
return $this->hasMany('App\Permission','role_id', 'role_id');
}
}
$permissions = User::find(Auth::user()->id)->Role()->permission();//未测试,不知是否可行
$permissions = User::find(1)->iwantpermissions;
one to one的类似。