If you're working with Laravel and using Jetstream and Fortify (tools that handle how users log in), you might want to change where people go after they log in. Right now, after someone logs in, they usually go to a page called /dashboard. But what if you want them to go somewhere else? It's actually pretty easy to change!

What is Fortify?

Fortify is like a helper in your app that takes care of logging in, signing up, resetting passwords, and things like that. When you use Jetstream, it uses Fortify to manage all the user login stuff for you.

How to Find the Right File to Change Redirects

To change where people go after they log in, we need to find the right file. It's called config/fortify.php. Here’s how you find it:

  • Go to your project folder.
  • Open the folder named config.
  • Find the file called fortify.php.

Changing the Redirect URL After Login

Once you have opened config/fortify.php, you’ll find a part called 'home'. This is the page where people go after they log in. It looks like this:

                    'home' => '/dashboard',
                  

But what if you don’t want them to go to the dashboard? Just change /dashboard to whatever page you like! For example, if you want them to go to a page called /welcome, it would look like this:

                    'home' => '/welcome',
                  

Now, after someone logs in, they will go to the /welcome page!

Sending Different People to Different Pages

If you want to be fancy and send different people to different pages (like sending admins to a special admin page), you can do that too!

1. First, you create a new class that decides where to send people:

                    namespace App\Http\Responses;

use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;

class LoginResponse implements LoginResponseContract
{
    public function toResponse($request)
    {
        return $request->wantsJson()
            ? response()->json(['two_factor' => false])
            : redirect()->route(auth()->user()->is_admin ? 'admin.dashboard' : 'dashboard');
    }
}

                  

2. Then, you tell Fortify to use this new class by going to FortifyServiceProvider and adding this:

                    public function boot()
{
    $this->app->singleton(
        \Laravel\Fortify\Contracts\LoginResponse::class,
        \App\Http\Responses\LoginResponse::class
    );
}
                  

Now, when admins log in, they go to the admin dashboard, and everyone else goes to the regular dashboard!

That’s it! Now you know how to change where people go after they log in to your app. You can send everyone to the same page, or even make different pages for different people. It's all up to you!

Just remember:

  • Open config/fortify.php.
  • Change the 'home' parameter to the page you want.
  • If you need something special, create a custom class to handle it.

This makes your app feel more organized and gives users a better experience!