[英]Authentification by username in laravel 7
您好,我想按名稱登錄我的用戶,我已經這樣做了(與文檔相同:
public function username()
{
return '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'
我已經資助了我的問題。
我必須指定搜索偽的好值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.