Home > Mobile >  laravel: how to include files in routes / web.php to make using git easier
laravel: how to include files in routes / web.php to make using git easier

Time:01-10

please I have a little sourci we are several fulstack developers and we use git I would like everyone to have their route file for example web1.php and web2.php then use the require function to integrate into the file laravel routes / web.php but it does not work

CodePudding user response:

If you want separate route file, you can do this

Project Tree

|-- Project
   |-- ...
   |-- routes
      |-- other
         |-- other_route.php
      |-- web.php

Include your other route file in web.php

// web.php
Route::prefix('other')->name('other.')->group(__DIR__ . '/other/other_route.php');
...

// other_route.php
Route::get('/', [SomeController::class, 'index']);
...

If you use artisan, run php artisan route:list to check registered route

It works with either api.php and web.php.

CodePudding user response:

You can have multiple route files by using different middleware for each route file. after creating your route file in routes folder you should add your file to RouteServiceProvider.php inside boot() function like this.

 /**
 * Define your route model bindings, pattern filters, etc.
 *
 * @return void
 */
public function boot()
{
    $this->configureRateLimiting();

    $this->routes(function () {
        Route::prefix('user_prefix')
            ->middleware('user_middleware')
            ->namespace($this->namespace)
            ->group(base_path('routes/userroute.php'));
    });
}

Then stop server if it's running and run

php artisan config:clear

then restart your server.

  •  Tags:  
  • Related