【发布时间】:2017-05-25 17:11:47
【问题描述】:
当用户尝试登录但用户名和密码在表中不匹配时,我有一个小问题,如何返回登录页面并显示错误消息
login.blade.php
<form class="login-box animated fadeInUp" action="valdateData" method="POST" >
{{csrf_field()}}
<div class="box-header">
<h2>Log In</h2>
</div>
<label for="username">Username</label>
<br/>
<input type="text" id="username" name="username">
<br/>
<label for="password">Password</label>
<br/>
<input type="password" id="password" name="password">
<br/>
<button type="submit">Sign In</button>
<br/>
<a href="#"><p class="small">Forgot your password?</p></a>
</form>
web.php
Route::post('/testgetvalue','OrdersController@GetValues');
Route::get('/ES','OrdersController@PrepareIndex');
Route::get('/loginForm','LoginController@ShowLoginPage');
Route::post('/valdateData','LoginController@checkValidate');
Route::post('login/{id}','LoginController@ShowErrorMassege');
LoginController.php
public function ShowLoginPage()
{
return view('/loginForm');
}
public function checkValidate(Request $request)
{
$username=$request->input('username');
$password=$request->input('password');
$isVald=true;
$checkValdate = \DB::table('authentications')
->where(['username'=>$username,'password'=>$password])
->get();
if(count($checkValdate) > 0)
{
$isVald=true;
session()->set('UserValidate','true');
session()->set('username',$username);
//$value=session()->get('test');
// echo "session "+$value;
return redirect('/es');
} else {
return redirect('/login/'.$isVald);
}
}
在这部分
return redirect('/login/'.$isVald);
如何返回登录页面并显示错误消息
谢谢
【问题讨论】:
-
你正在使用 php artisan make:auth?
-
不,我正在使用自定义表格
-
您可以使用
with()函数。return redirect('/login/'.$isVald)->with('status', 'Error message!');然后您的会话中将有status。