Redirect to the last action after login

Posted 10 months ago by Karisme

Hello,

I come to you because I want to redirect the user to this last action after connecting.

I use the auth middleware to redirect to the login if it is not authenticated.

Here is my RedirectIfAuthenticated middleware:

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect()->intended('/');
        }

        return $next($request);
    }
}

It allows me to redirect the user to the url of this last action but without the right method and without the previous inputs filled.

Thank you for your answers.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.