Skip to content
Advertisement

How do you add a route to Fortify in Laravel 8?

I have Laravel with Jetstream installed. How can I add a route to Fortify?

I’ve read through the whole readme:

https://github.com/laravel/fortify/blob/1.x/README.md

That readme provides ways to customize functionality but it doesn’t show a way to add a new route to Fortify.

I can see the routes.php file in

/vendor/laravel/fortify/routes/routes.php

but you’re not supposed to edit stuff in the vendor folder. If you edit anything inside the vendor folder, whenever you run a Composer update it will overwrite any of your changes when the files update.

Typically I think you’d have to do some sort of artisan command to get proper access to the corresponding files by publishing Fortify’s resources like:

php artisan vendor:publish --provider="LaravelFortifyFortifyServiceProvider" 

This would publish Fortify’s actions to your app/Actions folder, etc

How can I add a new route to Fortify in the right way?

Advertisement

Answer

You should never touch or mess with vendor as it is immaculate.

By default the fortify routes located on /vendor/laravel/fortify/routes/routes.php, but you shouldn’t edit anything inside the vendor folder otherwise whenever you run composer update it will overwrite any of your changes when the files update.

You can simply do the same on /routes/web.php with fortify middleware :

Route::group(['middleware' => config('fortify.middleware', ['web'])], function () {

    // with fortify guest middleware
    Route::get('foo', function () {
       return 'Foo';
    })->middleware(['guest']);

    // with fortify auth middleware
    Route::get('bar', function () {
       return 'bar';
    }) ->middleware(['auth']); // fortify auth middleware

});
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement