0
save guys, I want to know how to project my admin route so that the user does not have access to this route but they both have to be authenticated.
My routes
Route::group(['middleware' => ['auth']], function () {
Route::get('/Admin', function () { //ADM ADM
return "Seu ID: " . Auth::user()->id . " Você é ADM";
})->name('admin');
Route::get('/Usuario', function () { //USER USER
return "Seu ID: " . Auth::user()->id . " Você é Usuario";
})->name('usuario');
Route::get('/semLogar', function () { // SEM LOGAR
return "Você não está autenticado";
})->name('semLogar');
Route::get('/login/admin',['middleware' => 'Check:admin','uses' => 'AdminController@index', 'as' => 'indexAdm']);
});
My handler
public function index (){
return "Opa controller adm";
}
Middleware
public Function Handle($request, Closure $next, $role) { if (!Auth::check()) {
return redirect()->route('semLogar');
}
if(Auth::user()->role == $role){
return redirect()->route('admin');
} else if (Auth::user()->role !== $role){
return redirect()->route('usuario');
}
return $next($request);
}
middlewareGroups
'CheckGrupo' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'Check' => \App\Http\Middleware\CheckAdmin::class,
],
routeMiddleware
'Check' => \App\Http\Middleware\CheckAdmin::class,
What I want is that when the user is logged in he could not put in the /admin URL and enter the /admin route that he can only enter if he is Adm.
NOTE: I am registering in the bank an ENUM('user','admin').
vlw man helped GOD a lot
– Joan Marcos