I have used validator from laravel but I want to add a custom rule if the user is not a authenticated user. Here is what I have done:
public function postSignIn(){
$validator = Validator::make(Input::all(),
array(
'email' => 'required|email',
'password' => 'required'
)
);
if($validator->fails()){
//return error message
return Redirect::to('account/signin')
->withErrors($validator)
->withInput(Input::except('password'));
}
else{
$remember = (Input::has('remember')) ? true:false;
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1
),$remember
);
if($auth){
return Redirect::intended('/')
->with('global', 'Welcome');
}
else{
return Redirect::to('account/signin')
->withErrors($validator, 'login');
}
}
And this is my view to display the error
@if ($errors -> has())
<div class="alert-danger alert-dismissible fade in" role="alert" style="padding: 0.5em;">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
@foreach($errors->all() as $error)
{{ $error }}<br />
@endforeach
</div>
@endif
The validation for form works fine but I am having problem to display the error for unauthenticated user. So, any help would be appreciated very much.