我只想在表单无法验证的情况下添加getErrors和getInput。我试图找出如何将其添加到重定向变量。
/**
* Store a newly created user in storage.
*
* @return Response
*/
public function store()
{
$input = Input::all();
$message = 'The form failed to validate.';
$redirect = Redirect::to('users/create');
$validation = Validator::make($input, $rules);
if ($validation->fails())
{
$message = 'The form failed to validate';
// add on ->getErrors()->getInput();
}
User::create([
'username' => $input['username'],
'email_address' => $input['email_address'],
'password' => $input['password'],
'role_id' => $input['role']
]);
return $redirect->with('message', $message);
}
答案 0 :(得分:0)
if ($validation->fails())
{
$message = 'The form failed to validate';
$redirect->withErrors($validation)->withInput();
}