DanielPahor DanielPahor - 1 year ago 80
PHP Question

Redirecting after login to authorised user's relationship

After my users log in I want them to be redirected to a route which contains a slug of one of the models they are related to. I have edited the $redirectTo variable in the auth controller like this:

protected $redirectTo = '/auth()->user()->country->slug';

I have also tried

protected $redirectTo = '/{{auth()->user()->country->slug}}';

I am getting a property of non object error for both.

Any solution to this, so I can redirect my users to the route which contains the slug of their respective state?

Answer Source

try to override redirectPath method in your AuthController

public function redirectPath()
    return auth()->user()->state->slug;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download