【问题标题】:My Laravel Auth::attempt() function not working我的 Laravel Auth::attempt() 函数不起作用
【发布时间】:2021-01-02 12:30:03
【问题描述】:

这是我的控制器

 if($request->isMethod('post')){
        $data = $request->input();
        if(Auth::attempt(['email'=>$data['username'],'password'=>$data['password'],'user_type'=>'2'])){                
            return redirect('/business/dashboard');

【问题讨论】:

  • 好的...你有什么问题?
  • 条件未检查。
  • 您是如何存储您尝试登录的用户的?他们是否有一个名为user_type 的字段等于2
  • 是的,我有一个 user_type
  • 你是如何存储这个用户的? $data['username'] 有邮箱地址吗?当您存储用户时,您是否对他们的密码进行了哈希处理? user_type 是否等于 2

标签: php laravel authentication


【解决方案1】:

尝试使用此代码:如果 user_type 列类型为整数,则给出 2 不带引号,否则相同的代码和密码必须是 hash::make 否则 auth::attempt 将不起作用。

     if($request->isMethod('post')){
     $user = User::where(['email'=>$request['username'],'user_type'=>'2'])->first();
    if(!empty($user)){
 if(Auth::attempt(['email'=>$request['username'],'password'=>$request['password']])){                
        return redirect('/business/dashboard');
    }
   abort(404);

【讨论】:

    猜你喜欢
    • 2013-02-27
    • 2014-12-17
    • 1970-01-01
    • 2017-03-31
    • 2016-05-17
    • 2017-01-06
    • 2018-02-27
    • 2017-03-10
    相关资源
    最近更新 更多