Dylan Glockler
Dylan Glockler

Reputation: 1219

Laravel 5.3 determine redirection based on factors

I realize that I can change where my user is directed after login by changing

    protected $redirectTo = '/home';

in the LoginController.php

However, I want to check if there are any items in a shopping cart and if so, direct the user to the checkout page. I may also check to see if they have purchased a service that is active and direct them to the dashboard, then anyone else to the homepage.

Anyone know how to apply some logic to the redirection?

Upvotes: 1

Views: 41

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163838

You can override sendLoginResponse() method in app\Http\Controllers\Auth\LoginController.php to perform the check and redirect to whatever route you want.

Original sendLoginResponse() method is in vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php. Copy-paste it to LoginController.php and then work with it. Do not change anything in an original trait.

Upvotes: 1

Related Questions