如何在Laravel 5表单请求中使用请求路由参数?
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 个解决方案
#1
46
That's very simple, just use the route()
method. Assuming your route parameter is called id
:
这非常简单,只需使用route()方法。假设您的路由参数名为id:
public function authorize(){
$id = $this->route('id');
}
更多相关文章
- 使用mysql验证在php中登录表单
- 防止Ajax创建表单的默认值
- php 封装原生数据导出的方法
- 在PHP和MySQL中同时插入来自多个表单的多个值
- PHP限制HTML内容中图片必须是本站的方法
- php连接mysql的三种方法
- PHP中使用cURL实现Get和Post请求的方法
- 如何使用PHP在表单中找到移动复制
- 怎么知道php代码运行时调用了那个类、那个方法呢?