最佳答案
如何在 Laravel 重定向的视图中显示验证消息?
这是我在控制器中的函数
public function registeruser()
{
$firstname = Input::get('firstname');
$lastname = Input::get('lastname');
$data = Input::except(array('_token')) ;
$rule = array(
'firstname' => 'required',
'lastname' => 'required',
) ;
$validator = Validator::make($data,$rule);
if ($validator->fails())
{
$messages = $validator->messages();
return Redirect::to('/')->with('message', 'Register Failed');
}
else
{
DB::insert('insert into user (firstname, lastname) values (?, ?)',
array($firstname, $lastname));
return Redirect::to('/')->with('message', 'Register Success');
}
}
我知道下面给出的代码是一个糟糕的尝试,但我怎样才能修复它和什么是 我失手了
@if($errors->has())
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
@endif