user859375 user859375 - 2 months ago 14
PHP Question

Property redirectPath and redirectTo set location? Laravel trait AuthenticatesAndRegistersUsers

In Laravel 5.0, the method redirectPath in trait AuthenticatesAndRegistersUsers checks if property redirectPath or redirectTo exists or not. If it does, the user is redirected to that path.

The question is, where is it set? I understand that its set to the page user was trying to load before she was redirected to /auth/login page. However, I can't figure out where is this being set.

public function redirectPath()
if (property_exists($this, 'redirectPath'))
return $this->redirectPath;

return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';


By default it's not set at all!! That's why the function needs to check for it with property_exists(). You can set it anywhere you have imported the trait with use AuthenticatesAndRegistersUsers.

In the default Laravel installation that would be the AuthController:

class AuthController extends Controller {

    use AuthenticatesAndRegistersUsers;

    protected $redirectTo = '/foo/bar';

    // ...