Post-login redirection

When a user logs in, Laravel will redirect them to a page defined by the $redirectTo attribute in the login controller. Let's change this from /home to /.

app/Http/Auth/Controllers/LoginController.php:

class LoginController extends Controller
{
  ...

  protected $redirectTo = '/';

  ...
}

Let's also update the RedirectIfAuthenticated middleware class so that if a logged-in user attempts to view the login page, they're redirect to / (instead of the default /home value.)

app/Http/Middleware/RedirectIfAuthenticated.php:

...

if (Auth::guard($guard)->check()) {
  return redirect('/');
}

With that done, our login process will now work correctly.

Get Full-Stack Vue.js 2 and Laravel 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.