如果资源属于我在 Laravel 5 中为其创建删除请求的用户,我将尝试授权对资源的删除请求。
对于另一个资源,我可以做类似的事情:
public function authorize()
{
if(Pivot::findOrFail($this->route('pivots'))->user_id != Auth::user()->id){
return false;
}
return true;
}
所以基本上 $this->route('pivots')
会返回用户试图删除的枢轴的 ID,我会检查它是否属于当前用户。
但现在我正在尝试与此类似的另一种资源:
public function authorize()
{
if(CropSection::findOrFail($this->route('crop-sections'))->pivot->user_id != Auth::user()->id){
return false;
}
return true;
}
我试图死掉并转储 $this->route('crop-sections')
结果是 null 但请求是 http://localhost:8000/crop-sections/10
id 为 10.
我做错了什么?
最佳答案
关于php - 无法从 Laravel 5 删除请求中的路由访问资源 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31181614/