DEV Community

Cover image for Laravel Breeze Change Redirect After Login/Register
Saddam Hossain
Saddam Hossain

Posted on

Laravel Breeze Change Redirect After Login/Register

In this post, I will show you how to change redirect url after login/register in laravel breeze.

After install laravel breeze you can update existing controller file. you just need to update AuthenticatedSessionController.php and RegisteredUserController.php file. You Can Learn How to Customize Laravel Breeze Authentication

Laravel Breeze Change Redirect After Login/Register
Lets Start Laravel Breeze Change Redirect After Login/Register
By default, after login it will redirect to “dashboard” route but you can change it to “home” url like the following way:

We will change it for Login:

app/Http/Controllers/Auth/AuthenticatedSessionController.php

/**
 * Handle an incoming authentication request.
 */
public function store(LoginRequest $request): RedirectResponse
{
    $request->authenticate();

    $request->session()->regenerate();

    return redirect()->intended(route('dashboard', absolute: false));
}
Enter fullscreen mode Exit fullscreen mode

Change redirect it to:

return redirect()->intended(route('home'));
Enter fullscreen mode Exit fullscreen mode

Now, you can change for Register:

app/Http/Controllers/Auth/RegisteredUserController.php

/**
 * Handle an incoming registration request.
 *
 * @throws \Illuminate\Validation\ValidationException
 */
public function store(Request $request): RedirectResponse
{
    $request->validate([
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
        'password' => ['required', 'confirmed', Rules\Password::defaults()],
    ]);

    $user = User::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => Hash::make($request->password),
    ]);

    event(new Registered($user));

    Auth::login($user);

    return redirect(route('dashboard', absolute: false));
}
Enter fullscreen mode Exit fullscreen mode

Change redirect it to:

return redirect(route('home'));

Enter fullscreen mode Exit fullscreen mode

I hope it can help you…
You Can Learn

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay