对于我的API,我需要返回一个具有相应权限的角色。
模特角色:
public function permissions()
{
return $this->belongsToMany( Permission::class );
}
模型权限:
public function roles()
{
return $this->belongsToMany( Role::class );
}
当我从RoleController使用以下功能时:
/**
* Show the form for editing the specified resource.
*
* @param \App\Role $role
* @return \Illuminate\Http\Response
*/
public function edit( Role $role )
{
return response()->json( $role->with('permissions')->first(), 200 );
}
我只能从角色中得到第一个结果,即使我发不同的角色也很难$role
。表示我发送角色2
还是3
从角色获得结果1
。
但是,我还检查了$role
确实返回了正确角色的(2
)
角色的权限1
确实很困难,所以主要的问题是为什么我只能从数据库中得到第一个结果?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句