authentication - How to change the default behavior of intended method in laravel when redirecting users 11 - Stack Overflow

admin2025-04-28  2

i have a website without login page. actually my login form is a pop up form that can be showed in any page when user click on the login/register button. i want to redirect my authenticated users to their intended page (the page that they clicked on it when they wasn't authenticated)

but intended method in laravel will only work if the user was redirected to the login page before submitting the form. If they weren't redirected to the login page, Laravel will redirect them to the home page instead.

how can we change this default behavior?

my login controller

public function loginHandler(AuthLoginRequest $request)
    {
        $credentials = $request->only('email', 'password');
        if (Auth::attempt($credentials)) {
            return redirect()->intended()->with('message', 'welcome dear user');

        } else {

            return redirect()->route('customer.home')->with('message', 'no user found, try again');
        }

    }

my customAuth Middleware

public function handle(Request $request, Closure $next): Response
    {
        if (!Auth::check()) {
            return redirect()->intended()->with('message', 'first, login into your account');
        }
        return $next($request);
    }
转载请注明原文地址:http://anycun.com/QandA/1745855563a91277.html