且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 5如何验证路由参数?

更新时间:2023-11-26 13:48:40

对于Laravel< 5.5:
这样做的方法是像这样覆盖CheckTokenServerRequestall()方法:

For Laravel < 5.5:
The way for this is overriding all() method for CheckTokenServerRequest like so:

public function all() 
{
   $data = parent::all();
   $data['token'] = $this->route('token');
   return $data;
}

编辑
对于Laravel> = 5.5:
上述解决方案在 Laravel<中工作. 5.5 .如果要在 Laravel 5.5或更高版本中使用它,则应使用:

EDIT
For Laravel >= 5.5:
Above solution works in Laravel < 5.5. If you want to use it in Laravel 5.5 or above, you should use:

public function all($keys = null) 
{
   $data = parent::all($keys);
   $data['token'] = $this->route('token');
   return $data;
}

相反.