Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property redirectPath and redirectTo set location? Laravel trait AuthenticatesAndRegistersUsers

Tags:

php

laravel

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';
}
like image 944
user859375 Avatar asked Mar 11 '15 08:03

user859375


1 Answers

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';

    // ...
}
like image 153
lukasgeiter Avatar answered Nov 13 '22 16:11

lukasgeiter