作者:郭昊天886688 | 来源:互联网 | 2023-01-31 14:31
I am new to Laravel 5 and I am trying to use the new Form Request to validate all forms in my application.
我是Laravel 5的新手,我正在尝试使用新的表单请求来验证我的应用程序中的所有表单。
Now I am stuck at a point where I need to DELETE a resource and I created a DeleteResourceRequest for just to use the authorize method.
现在我被卡住了,我需要删除一个资源,我创建了一个DeleteResourceRequest用于仅仅使用授权的方法。
The problem is that I need to find what id is being requested in the route parameter but I cannot see how to get that in to the authorize method.
问题是我需要在route参数中找到被请求的id,但是我不知道如何将其传递给authorize方法。
I can use the id in the controller method like so:
我可以在controller方法中使用id,如下所示:
public function destroy($id, DeletePivotRequest $request)
{
Resource::findOrFail($id);
}
But how to get this to work in the authorize method of the Form Request?
但是如何在表单请求的授权方法中使其工作呢?
4 个解决方案