Laravel login redirect based on role code example

Example 1: 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');  }}

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

protected $redirectTo = RouteServiceProvider::HOME;

Tags:

Php Example