Laravel 5.4 redirection to custom url after login

前端 未结 9 2194
悲哀的现实
悲哀的现实 2020-11-28 09:46

I am using Laravel Framework 5.4.10, and I am using the regular authentication that

php artisan make:auth

provides. I want to protect the

9条回答
  •  无人及你
    2020-11-28 10:10

    The way I've done it by using AuthenticatesUsers trait.

    \App\Http\Controllers\Auth\LoginController.php

    Add this method to that controller:

    /**
     * Check user's role and redirect user based on their role
     * @return 
     */
    public function authenticated()
    {
        if(auth()->user()->hasRole('admin'))
        {
            return redirect('/admin/dashboard');
        } 
    
        return redirect('/user/dashboard');
    }
    

提交回复
热议问题