Php 通过Laravel 4验证的成功或失败 我在我的REST用户控制器内部创建一个用户表单。当用户在表单上时,我将其当前发布到store方法。当表单提交到方法时,我希望它验证用户输入,然后重定向回create方法,以便在数据验证失败时显示成功消息或错误消息数组。有人可以指出需要什么来帮助我重定向到create方法,并根据验证测试给出一条成功消息或错误消息 /** * Store a newly created user in storage. * * @return Response */ public function store() { $input = Input::all(); $validation = Validator::make($input, $rules); if ($validation->fails()) { $messages = $validator->all(); } else { User::create([ 'username' => $input['username'], 'email_address' => $input['email_address'], 'password' => $input['password'], 'role_id' => $input['role'] ]); } return Redirect::to('users/create'); }

Php 通过Laravel 4验证的成功或失败 我在我的REST用户控制器内部创建一个用户表单。当用户在表单上时,我将其当前发布到store方法。当表单提交到方法时,我希望它验证用户输入,然后重定向回create方法,以便在数据验证失败时显示成功消息或错误消息数组。有人可以指出需要什么来帮助我重定向到create方法,并根据验证测试给出一条成功消息或错误消息 /** * Store a newly created user in storage. * * @return Response */ public function store() { $input = Input::all(); $validation = Validator::make($input, $rules); if ($validation->fails()) { $messages = $validator->all(); } else { User::create([ 'username' => $input['username'], 'email_address' => $input['email_address'], 'password' => $input['password'], 'role_id' => $input['role'] ]); } return Redirect::to('users/create'); },php,laravel,Php,Laravel,你可以用任何一个 $messages = $validator->messages(); 或 检索错误消息。如果要显示“flash”消息,可以在重定向中使用“with”方法 Redirect::to('user/currentroute')->with('message', 'Something wrong'); 有关详细信息,请阅读中的内容,然后了解all()函数是什么?至于我如何传递成功消息或失败消息,而不是实际的消息。你是说“登录失败”之类的消息吗???您可以在重定向返回

你可以用任何一个

$messages = $validator->messages();

检索错误消息。如果要显示“flash”消息,可以在重定向中使用“with”方法

Redirect::to('user/currentroute')->with('message', 'Something wrong'); 

有关详细信息,请阅读

中的内容,然后了解all()函数是什么?至于我如何传递成功消息或失败消息,而不是实际的消息。你是说“登录失败”之类的消息吗???您可以在重定向返回Redirect::to('user/login')->with('message','login Failed')中传递'with'方法;很好,但是,添加getErrors和getInput的最佳有效方法是什么,因为如果这是一篇成功的文章,我就不需要它们了。
Redirect::to('user/currentroute')->with('message', 'Something wrong');