【发布时间】:2020-07-19 21:27:48
【问题描述】:
您好,我想按名称登录我的用户,我已经这样做了(与文档相同:
public function username()
{
return 'username';
}
documentation of authenticate by username
如果我想登录表单,Laravel 将我重定向到登录表单而没有错误消息。
在我的 LoginController.php 中:
public function login(Request $request)
{
$input = $request->all();
$this->validate($request, [
'email' => 'required|email',
'password' => 'required',
'name' => 'required'
]);
if(auth()->attempt(array('name' => $input['name'], 'password' => $input['password'])))
{
//If an user is admin and if the account admin have all authorization he can pass et go to the admin pages
if (auth()->user()->is_admin == 1 && auth()->user()->is_seller == 1 && auth()->user()->is_client == 1) {
return redirect()->route('admin.dashboard');
//If user is an seller and user have pass the login, he have authorization, he can pass to go on seller dashboard
}elseif (auth()->user()->is_seller == 1 && auth()->user()->is_client == 1){
return redirect()->route('seller.dashboard');
//If the user is an seller he go to the shop page
} elseif(auth()->user()->is_client == 1){
return redirect()->route('shop.home');
}
}else{
return redirect()->route('login')
->with('error','Email-Address And Password Are Wrong.');
}
return route('login');
}
我已将字段名称替换为用户表的名称列 => name='name'
【问题讨论】:
标签: php mysql laravel authentication