laravel - 未使用自定义表单请求方法调用控制器方法
问题描述
对于表单验证,我做了一个Request class
via php artisan make:request UpdatePlanRequest
。
但是,在使用UpdatePlanRequest
store 中的类之后,不再调用该方法。
UpdatePlanRequest
: _
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePlanRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{ //TODO: CHECK IF THE PROTOTYPE IDS ARE OWNED BY THE USER (https://stackoverflow.com/questions/42662579/validate-an-array-of-integers/42693970)
return [
'start_date' => 'required|date',
'end_date' => 'required|date|after:start_date',
'name' => 'required|string'
];
}
}
控制器方法:
use App\Http\Requests\UpdatePlanRequest;
public function store(UpdatePlanRequest $request)
{
//
dd('hello');
}
如果显示了函数标头store(Request $request)
hello
,则在该示例中未显示。
根据文档$request->validated();
,为了验证目的,需要稍后调用自定义请求类。
解决方案
你有你的 Request 类是抽象的原因吗?运行时创建的默认类php artisan make:request <name>
没有将类定义为抽象类。这似乎对我有用,但在将其声明为抽象时无效。
推荐阅读
- r - 如何通过更新值来连接两个数据帧包含 r 中匹配 id 的重复项
- javascript - pg-promise UPDATE 返回成功返回码但实际上不更新表
- react-native - 不使用 React native 和 Flask/Flask jwt-extended 存储的 Cookie
- css - 响应式网站,使 div 全屏和用户向下滚动以查看其他人
- ubuntu-18.04 - 纱线安可产品失败
- sql - 如何找到具有相等值的行?
- git - 如何为 Django Wagtail 应用程序设置 Git 工作流?
- python - Python 动态变量调用
- javascript - 如何映射对象数组并使用javascript列出卡片中的每个对象并做出反应?
- javascript - 如何让 node.js 程序等待 PNG 解析?