该代码没有任何语法错误,但是不起作用。该代码似乎与数据库没有交互。
public function execute(Request $request) {
if($request->isMethod('post')) {
$messages = [
'required' => "Campo :attribute rellenado",
'email' => "Este :attribute campo debe rellenarse con su email"
];
$this->validate($request,[
'name' => 'required|max:255',
'email' => 'required|email',
'text' => 'required'
], $messages);
dump($request);
答案 0 :(得分:0)
修改您的规则
$messages = [
'name.required' => 'This Field Name is required ',
'name.max' => 'The name should be :max in length',
'email.required' => 'the email field is required',
'email.email' => 'the email should be valid email',
'text.required' => 'the the text is required',
];
$this->validate($request,[
'name' => 'required|max:255',
'email' => 'required|email',
'text' => 'required'
], $messages);
在这种情况下,dump($requset)
将不起作用,因为您使用的是请求特征,其中$this->validate
函数会在验证失败时自动重定向回
答案 1 :(得分:-1)
尝试将dump($request)
更改为dd($request)
if($request->isMethod('post')) {
$messages = [
'required' => "Campo :attribute rellenado",
'email' => "Este :attribute campo debe rellenarse con su email"
];
$this->validate($request,[
'name' => 'required|max:255',
'email' => 'required|email',
'text' => 'required'
], $messages);
dd($request);