ItSolutionStuff.com

Laravel Breeze Change Redirect After Login/Register

By Hardik Savani • October 14, 2024
Laravel

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.

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));
}

Change redirect it to:

return redirect()->intended(route('home'));

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));
}

Change redirect it to:

return redirect(route('home'));

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Integrate AdminLTE 3 in Laravel 11?

Read Now →

Laravel 11 Product Add to Cart Functionality Example

Read Now →

How to Install and Configuration Telescope in Laravel 11?

Read Now →

Laravel 11 Image Intervention Tutorial With Example

Read Now →

Laravel 11 Generate and Read Sitemap XML File Tutorial

Read Now →

Laravel 11 Stripe Payment Gateway Integration Example

Read Now →

Laravel 11 Dynamic Google Charts Integration Tutorial

Read Now →

Laravel 11 Drag and Drop File Upload with Dropzone JS

Read Now →

Laravel 11 Chart using Highcharts JS Example

Read Now →

Laravel 11 Many to Many Eloquent Relationship Tutorial

Read Now →

Laravel 11 Flash Message Example Tutorial

Read Now →

Laravel 11 Ajax CRUD Operation Tutorial Example

Read Now →

Laravel 11 Database Seeder Example Tutorial

Read Now →

Laravel 11 New a Health Check Route Example

Read Now →