DanielPahor DanielPahor - 2 months ago 5x
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?


try to override redirectPath method in your AuthController

public function redirectPath()
    return auth()->user()->state->slug;