Laravel 5.4 redirection to custom url after login

前端 未结 9 2206
悲哀的现实
悲哀的现实 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:26

    If you look in the AuthenticatesUsers trait you will see that in the sendLoginResponse method that there is a call made to $this->redirectPath(). If you look at this method then you will discover that the redirectTo can either be a method or a variable.

    This is what I now have in my auth controller.

    public function redirectTo() {
        $user = Auth::user();
        switch(true) {
            case $user->isInstructor():
                return '/instructor';
            case $user->isAdmin():
            case $user->isSuperAdmin():
                return '/admin';
            default:
                return '/account';
        }
    }
    

提交回复
热议问题