未定义类型Auth

namespace App\Http\Controllers; 

use Auth; 
use Illuminate\Http\Request;

class maincontroller extends Controller 
{ 
    public function home(Request $request)
    { 
        if(Auth::Attempt($request->only('email','password'))) { 
            return redirect('/'); 
        }
    }
}
评论
  • 花自毁
    花自毁 回复

    试试这个,\ Auth :: attempt([...]); 我认为这很有帮助

  • cnon
    cnon 回复

    You may use the auth helper instead and then no worries about any class name

    namespace App\Http\Controllers; 
    
    use Illuminate\Http\Request;
    
    class maincontroller extends Controller 
    { 
        public function home(Request $request)
        { 
            if(auth()->attempt($request->only('email','password'))) { 
                return redirect('/'); 
            }
        }
    }
    
  • 猪一样队友
    猪一样队友 回复

    Change the Auth namespace to:

    use Illuminate\Support\Facades\Auth;