【问题标题】:Authentification by username in laravel 7在 laravel 7 中通过用户名进行身份验证
【发布时间】: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


    【解决方案1】:

    我已经解决了我的问题。

    我必须指定搜索伪的好值

    【讨论】:

      猜你喜欢
      • 2015-09-09
      • 2019-09-18
      • 2021-07-18
      • 2016-04-23
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      相关资源
      最近更新 更多