My approach to this situation is using middleware as @sssurii told you
I have a roles table which states normal users and admin user, and additionally I have a middleware such the following:
namespace App\Http\Middleware; use Closure; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Response; class AdminMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $user = Auth::user(); if(!$user->role->title==='Admin'){ return route('user'); } return $next($request); } }
Then in kernel class, I've added that middleware in routes
protected $routeMiddleware = [ .... 'isAdmin' => \App\Http\Middleware\AdminMiddleware::class ];
Now you need to protect your admin routes, it is solver by
Route::group(['middleware' => ['auth', 'isAdmin'], 'prefix' => 'admin', 'as' => 'admin.'], function () { Route::get('/home', 'Admin\HomeController@index')->name('dashboard'); ..... }
Here you have a way to filter requests to admin routes, and let get in only users that belongs to group/role Admin. After that if you want an automatic redirect at login, you should modify redirectPath function in Auth controller (usually at app/http/controllers/auth/AuthController.php)
public function redirectPath() { if (\Auth::user()->role->title === 'Admin') { return redirect()->route('admin.dashboard'); } return redirect()->route('user.dashboard'); }