I am new to Laravel and i am working on login page in which i want throw error below input tags if login credentials are wrong. I have written some code and everything is working fine but errors are not showing.
Have a look at what I have done.
In Controller:
public function login(Request $req) {
$email = $req->input('email');
$password = $req->input('password');
$checkLogin = DB::table('admin')->where(['email'=>$email,'password'=>$password])->get();
if(count($checkLogin) > 0) {
echo "Login Successfull";
}
else {
// echo "Login Failed!";
return Redirect::route('admin-login')->with();
}
}
In View:
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
In Route:
Route::post('admin-login-result','AdminLoginController@login')->name('admin-log');
Thanks
Try this one in your else block
Redirect::back()->withErrors(['msg', 'The Message']);
In view file use like this
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif
Refer this link for more details https://itsolutionstuff.com/post/laravel-53-form-input-validation-rules-example-with-demoexample.html
You can use for login users
Auth::login($user);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With