3

I use in my application cms nova. I want to configure redirection according to the user property. Didn't find anything in the documentation. Maybe I just didn't understand. Please help to understand.

As I understand it, when Nova is used, it takes over the authentication process.

  • See: https://stackoverflow.com/questions/42177044/laravel-5-4-redirection-to-custom-url-after-login – Karl Hill Feb 03 '19 at 06:01
  • 1
    Possible duplicate of [Laravel 5.4 redirection to custom url after login](https://stackoverflow.com/questions/42177044/laravel-5-4-redirection-to-custom-url-after-login) – Karl Hill Feb 03 '19 at 06:03
  • Possible duplicate of [Laravel Nova Redirect to a custom path after login](https://stackoverflow.com/questions/54334986/laravel-nova-redirect-to-a-custom-path-after-login) – Nico Haase Aug 19 '19 at 08:50

3 Answers3

1

Add following protected method to override default redirection in your app/Http/Controllers/Auth/LoginController.php file:

protected function authenticated(Request $request, User $user)
{
    return redirect("/redirect_users_after_login");
}
Udhav Sarvaiya
  • 8,317
  • 11
  • 53
  • 61
0

Are you using Laravel Auth for authentication? If yes, you can just modify the available function ad redirect as per you requirement. Something like this:

In you login Controller:

protected function authenticated(Request $request, $user)
{
    //Check Role to user type
    if ( $user->isAdmin() ) {
        //Add redirection
        return redirect()->route('admin.route.name');
    }
    else {
      return redirect()->route('admin.route.name');
    }

}
Saurav
  • 345
  • 1
  • 3
  • 12
-1

in vendor/Laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUsers.php File below Code Is Exist

public function redirectPath()
    {

        if (method_exists($this, 'redirectTo')) {
            return $this->redirectTo();
        }


        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
    }

if you define function in LoginController.php as Bellow you can redirect users to their Path

 protected $redirectTo;
    protected function redirectTo()
    {

        if(\Auth::user()->hasRole('Administrator')){
            $this->redirectTo = '/admin/overview';
            return $this->redirectTo;
        }
        else if(\Auth::user()->hasRole('Doctor')){
            $this->redirectTo = '/doctor/overview';
            return $this->redirectTo;
        }
    }

THAT IS ALL YOU MUST DO!!!