Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use intended function in Laravel

I need to register in a tournament with the URL:

http://laravel.dev/tournaments/1/register/

This URL is in the middleware 'auth', so if the user is not logged, he is redirected to login / page.

What I need is to redirect to

http://laravel.dev/tournaments/1/register/

After login.

In my routes.php, I have:

Route::get('tournaments/{tournamentId}/register', 'TournamentController@register');

I was told to use

redirect()->intended

but I don't know how to do it.

In the general case, User will be redirected to /admin, but in this case, I want him to keep doing his main action ( Register tournament)...

I'm using the built in trait for login, so I checked what system do when login and it is already using this function:

protected function handleUserWasAuthenticated(Request $request, $throttles)
{
    if ($throttles) {
        $this->clearLoginAttempts($request);
    }

    if (method_exists($this, 'authenticated')) {
        return $this->authenticated($request, Auth::guard($this->getGuard())->user());
    }

    return redirect()->intended($this->redirectPath());
}

Thing is it will redirect me to a default path, not a dynamic one...

like image 547
Juliatzin Avatar asked Dec 20 '25 07:12

Juliatzin


1 Answers

You should to know different between Redirect To and Redirect Intended

Redirect Intended: redirects the user to where they were originally going

Redirect To: Redirect the user to the page **YOU** specify them to go.
like image 87
GrigorAtaryan Avatar answered Dec 22 '25 00:12

GrigorAtaryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!