error when visiting pages behind middleware while not logging in
Opened this issue · 1 comments
khaledapps commented
first I have made a new auth (admin)
and I made HomeController which has the following methods
public function __construct() {
$this->middleware('auth:admin');
}
public function index() {
return view('admin.dashboard.index');
}
when someone try to go to admin/dashboard an error comes:
"Route [login] not defined"
and when I change the middleware in __construct mehtod to 'admin'
everything goes fine except that Auth::user() returns null
I can't understand exactly what is the difference between 'admin' and 'auth:admin'
why 'admin' redirects to the login page but with Auth::user() is null
and 'auth:admin' returns Auth::user() correctly but doesn't redirect to login page
khaledapps commented
solved by using
$this->middleware('admin');
and
for getting the admin
Auth::guard('admin')->user();