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');
}

更多相关文章

  1. 使用mysql验证在php中登录表单
  2. 防止Ajax创建表单的默认值
  3. php 封装原生数据导出的方法
  4. 在PHP和MySQL中同时插入来自多个表单的多个值
  5. PHP限制HTML内容中图片必须是本站的方法
  6. php连接mysql的三种方法
  7. PHP中使用cURL实现Get和Post请求的方法
  8. 如何使用PHP在表单中找到移动复制
  9. 怎么知道php代码运行时调用了那个类、那个方法呢?

随机推荐

  1. 窥探SQL预编译内幕
  2. SQL里ROWCOUNT的使用
  3. [O]SQL SERVER下有序GUID和无序GUID作为
  4. 利用读写锁实现sqlite多线程写的问题
  5. 急~~!!!sqlconnection连接SQL2005数据库总出
  6. iBatis中sqlmap resultclass="java.lang.
  7. 关于mysql对字符串的数字的排序
  8. 在MySQL中选择行作为列?
  9. MS ACCESS jdbc.odbc连接。未找到数据源
  10. QT 使用QSqlQuery时候的 错误,。。。。