我想在用户输入错误的登录信息时给予用户视觉反馈。
public function doLogin()
{
$rules = array(
'email' => 'required|email',
'password' => 'required|min:3'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::route('login')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($userdata)) {
return Redirect::route('dashhome')
->withJsd('true');
} else {
return Redirect::route('login')
->withErrors(['wrongpw','Wrong E-mail address or Password']);
}
}
}
在我的登录视图中我有这个代码
@if ($errors->has('wrongpw'))
<script>
$.gritter.add({
title: 'Ups!',
text: "{{ $errors->first('wrongpw') }}",
class_name: 'warning',
time: ''
});
</script>
@endif
但这并不奏效。知道我犯了什么错误或者有关如何做得更好的建议吗?
由于
答案 0 :(得分:1)
我认为你没有在正确的关联数组中传递错误,
试
->withErrors(array('wrongpw' => 'Wrong E-mail address or Password'));
或
->withErrors(['wrongpw' => 'Wrong E-mail address or Password']);