Hello,
I'm very confused with all the verification options on Laravel.
Using laravel 8.
I want to allow only certain roles to access my admin dashboard.
I have this middleware:
public function handle(Request $request, Closure $next)
{
if(Auth::user()->hasRole('Admin') || Auth::user()->hasRole('User') || Auth::user()->hasRole('Super Admin'))
return $next($request);
else
abort(401);
}
I have a folder under controllers called: Admin
In this folder I have an AdminController and in it:
public function __construct()
{
$this->middleware(['auth', 'admin']);
}
I have a custom route file called: admin.php under the routes folder.
In this file I have this:
Route::group(['middleware' => ['auth', 'admin']], function() {}
In RouteServiceProviders I added:
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace('App\Http\Controllers')
->group(base_path('routes/web.php'));
Route::middleware('web')
->namespace('App\Http\Controllers\Admin')
->group(base_path('routes/admin.php'));
});
}
The problem is if I add this: Auth::routes(['verify' => true]); to the route file (routes/admin.php) I get this error:
Target class [App\Http\Controllers\Admin\App\Http\Controllers\Auth\LoginController] does not exist.
Do I need it? If so how do I fix this problem? Doesn't the Route::group(['middleware' => ['auth', 'admin']] enough to protect the route?
So many options to protect routes I got lost.
I don't really understand the Auth::routes('verify' => true]) function. I read about it and still don't understand.
Can anyone please help?