Laravel - 如果登录凭据错误,则在同一页面上显示错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48820704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - Show error on the same page if login credentials are wrong
提问by user9332352
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.
我是 Laravel 的新手,我正在登录页面上工作,如果登录凭据错误,我想在输入标签下方抛出错误。我写了一些代码,一切正常,但没有显示错误。
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
谢谢
回答by Sathishkumar Rakkiasamy
Try this one in your else block
在你的 else 块中试试这个
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
有关更多详细信息,请参阅此链接https://itsolutionstuff.com/post/laravel-53-form-input-validation-rules-example-with-demoexample.html
回答by keshav khandelwal
You can use for login users
您可以用于登录用户
Auth::login($user);