650 0 0 0
Last Updated : 2025-04-28 22:18:01
In this snippet I will teach you how to create multiple route files instead of one file
Hello guys,
In this snippet I will teach you how to create multple route files to use in your project instead of one file
there are 2 ways you can go with :
First:
you can do this through app/Providers/RouteServiceProvider like this
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
Route::prefix('manager') // add your prefix here
->middleware('web')
->group(base_path('routes/manager.php')); // name of the new routes file
});
}
Second:
include all wanted route files inside the web route file using the code below
require __DIR__ . '/manager.php'; // use your wanted route file name
OR
require_once "manager.php"; // require once will check if file is already loaded or not , if loaded already it will not load it again
OR
require "manager.php"; // require will load the file every time