undefined type Auth

Viewed 17515
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('/'); 
        }
    }
}
4 Answers

Change the Auth namespace to:

use Illuminate\Support\Facades\Auth;

Try this :

\Auth::attempt([...]);

I think this is helpfull..

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('/'); 
        }
    }
}
  1. Use the Auth namespace to:

use Illuminate\Support\Facades\Auth;

Related