我正在尝试在Laravel 5.2中验证用户类型。路由如下:
Route::group(['middleware' => ['web']], function(){
Route::auth();
Route::get('/user/department/login', ['as' => 'department_login', 'uses' => 'DepartmentUserAuth\AuthController@showLoginForm']);
Route::post('/user/department/login','DepartmentUserAuth\AuthController@deptLoginPost');
});
而 AuthController.php
是
public function deptLoginPost(Request $request)
{
$this->validate($request, [
'username' => 'required',
'password' => 'required',
]);
if (auth()->guard('department_user')->attempt(['username' => $request->input('username'), 'password' => $request->input('password')]))
{
$user = auth()->guard('department_user')->user();
dd($user);
}else{
return redirect('/user/department/login')->with('message', 'Invalid credentials');
}
}
login.blade.php
是登录页面:
@if(Session::has('message'))
<div class="row">
<div class="col-lg-12">
<div class="alert {{ Session::get('alert-class', 'alert-info') }}">
<button type="button" class="close" data-dismiss="alert">×</button>
{!! Session::get('message') !!}
</div>
</div>
</div>
@endif
{{ dump(session()->all()) }}
但是
Session::has('message')
为空,并且dump
如下所示:array:3 [▼
"_token" => "BvQ630KrUl78Ngb8d3cst6pAIqenra3ohbYbLzAP"
"_previous" => array:1 [▼
"url" => "http://localhost:8080/material/public/user/department/login"
]
"flash" => array:2 [▼
"old" => []
"new" => []
]
]
我该如何在我的
login.blade.php
文件中显示所有错误信息(就像默认的身份验证控制器中一样)?
config/auth.php
代码。 - Basheer Kharoti$request->request->add(['message' => "您的自定义消息"]);
,而无需将其放入会话中。使用withInput()
重定向回去。 - Rutvij Kothari