Search code examples
phplaravellaravel-5.3

Laravel redirect to other pages after successfull login


I have three different types of users in my users table and after each success full login each specific type of user needs to be redirected to specific page according to role assigned in user table I read the documentation and tried different methods like redirectTo and protected properties. But they did not work for me.

If any one have a better solution to come up with this problem please share.

Note : please do not give route solutions.


Solution

  • In Laravel 5.3 you can override authenticated() method in LoginController.php. For example:

    protected function authenticated()
    {
        if (auth()->user()->type === 1) {
            return redirect()->route('admin.dashboard');
        } elseif (auth()->user()->type === 2) {
            return redirect()->route('client.dashboard');
        }
    }