multiple route files instead of one file

516 0 0 0

Last Updated : 2024-04-26 00:24:07

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

 


 

Mahmoud Anwar

Mahmoud Anwar

Back End Developer with a passion for developing innovative web applications that expedite the efficiency and effectiveness of organizational success. Well-versed in technology and writing code to create systems that are reliable and user-friendly. Also has the proven ability to motivate, educate, and collaborate effectively to build web applications and effectively track changes. Confident communicator, strategic thinker, and innovative creator to develop software that is customized to meet a company’s organizational needs, highlight their core competencies, and further their success.