Skip to content

Conversation

antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Dec 21, 2016

Adds call of redirectTo method in Illuminate\Foundation\Auth\RedirectsUsers trait.

It's pretty same as property $this->redirectTo, but if we will have method - there would be an ability to write custom redirect logic after authentication, registration or password reset. For example we can resolve where user should be redirected by using retrieved data from user data, session, cookies, etc...

If there is no redirectTo() method exists in your controller - redirectTo property will be used.

I thought about name of the method. Just left same as property. Another one was: resolveRedirectTo().

@antonkomarev antonkomarev changed the title Add auth redirect path generation method [5.3] Add auth redirect path generation method Dec 21, 2016
@taylorotwell taylorotwell merged commit 794b260 into laravel:5.3 Dec 21, 2016
@antonkomarev antonkomarev deleted the feature/dynamic-redirect-path branch December 21, 2016 15:49
@antonkomarev
Copy link
Contributor Author

Documentation added.

@tortuetorche
Copy link
Contributor

tortuetorche commented Jan 23, 2017

This new feature broke my ControllerAdditions::redirectTo() method with a Missing argument 1 for App\Http\Controllers\Controller::redirectTo() Exception...
I'm going to fix it.

@tortuetorche
Copy link
Contributor

tortuetorche commented Jan 23, 2017

FYI, here my workaround:
To keep backward compatibility, in my App\Http\Controllers\Auth\LoginController class, I replace the redirectTo() call to redirectUserTo().

//...
class LoginController extends Controller
{
    //...

    /**
     * Get the post register / login redirect path.
     * And keep Efficiently\JqueryLaravel\ControllerAdditions::redirectTo()
     *
     * @see https://github.com/efficiently/jquery-laravel/issues/1
     * @return string
     */
    public function redirectPath()
    {
        if (method_exists($this, 'redirectUserTo')) {
            return $this->redirectUserTo();
        }
        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
    }
}

So my ControllerAdditions::redirectTo() method works again 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants