am working on a project, i want to check if a user is an admin, if he is not an admin, he will be redirected to the login page, but if he is an admin, he will be redirected to the admin page, i initially made it the home url but later changed it to login url, so if the user is an admin it will redirect to the ad min url but if his not, it will still he redirection to the home url instead of the login url that i changed it to here is the admin url code
<?php
namespace App\Http\Middleware;
use Closure;
class Admin{
public function handle($request, Closure $next){
if(auth()->user()->isAdmin == 1){
return $next($request);
}
return redirect('login')->with('error','You have not admin access');
}
}
here is the web.php code
Route::get('/', 'PagesController@index');
Route::get('/about', 'PagesController@about');
Route::get('/dashboard', 'DashboardController@index');
Auth::routes();
Route::get('admin/routes', 'AdminController@index')->middleware('admin');
pls how can i solve this issue or what am i doing wrong
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire