redirect on login laravel based on user role code example

Example 1: how to redirect a particular user role to a page after login laravel

public function redirectTo() {  $role = Auth::user()->role;   switch ($role) {    case 'admin':      return '/admin_dashboard';      break;    case 'seller':      return '/seller_dashboard';      break;     default:      return '/home';     break;  }}

Example 2: how to redirect a particular user role to a page after login laravel

<?phpnamespace App\Http\Middleware;use Closure;use Illuminate\Auth\Middleware\Role as Middleware;use Illuminate\Support\Facades\Auth;class Role {  public function handle($request, Closure $next, String $role) {    if (!Auth::check()) // This isnt necessary, it should be part of your 'auth' middleware      return redirect('/home');    $user = Auth::user();    if($user->role == $role)      return $next($request);    return redirect('/home');  }}

Tags:

Php Example