Laravel 5.3 - Custom Redirect Logic After Authentication

Laravel 5.3 - Custom Redirect Logic After Authentication

Jan 7, 2017,

If you need redirect all users to the same page after successfull authentication just use protected property $redirectTo.

But if you need custom logic this approach won't work.

Laravel uses RedirectUsers::redirectPath() to get redirect path. So, just overwrite redirectPath() method in your controller.

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    //protected $redirectTo = '/';
    public function redirectPath()
    {
        // ...
        // custom logic here 
        // ...

        return '/my/custom/url/here';
    }

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }
}

The same approach will work for RegisterController and ResetPasswordController.