Crossroad

Redirect after Login or Register: Add your own Method

In Laravel’s Auth system you can customize a few most important things – one of them is a variable $redirectTo – where to take the user after login/registration. But there’s even more to customize.

By default, our app/Http/Controllers/Auth/RegisterController.php has this variable:

Which means – after registration, user is redirected to /home. And we can change it here, easily, by just changing this variable.

But what if, in your case, it’s more than a simple variable?

What if you want to redirect user to somewhere, depending on their role or some other case? You can define it as a separate method with the same name.

Basically, we can add any logic we want inside that method, and it will override the variable $redirectTo.

We can do same thing with LoginController.

You can read more about customizations in Auth – in the official documentation.

Liked the article? Maybe you need help with your Laravel project?
Check out my Upwork profile and hire me!

One thought on “Redirect after Login or Register: Add your own Method

  1. Hy Povilas, nice tutorial I’m beginning in Laravel and this article help me to understand a little more about this framework! Brazil say hello.

Leave a Reply

Your email address will not be published. Required fields are marked *