Dust out your bloated route file

Dust out your bloated route file and split it up to keep things organized

1class RouteServiceProvider extends ServiceProvider
2{
3 public function boot()
4 {
5 $this->routes(function () {
6 Route::prefix('api/v1')
7 ->middleware('api')
8 ->namespace($this->namespace)
9 ->group(base_path('routes/api.php'));
10 
11 Route::prefix('webhooks')
12 ->namespace($this->namespace)
13 ->group(base_path('routes/webhooks.php'));
14 
15 Route::middleware('web')
16 ->namespace($this->namespace)
17 ->group(base_path('routes/web.php'));
18 
19 if ($this->app->environment('local')) {
20 Route::middleware('web')
21 ->namespace($this->namespace)
22 ->group(base_path('routes/local.php'));
23 }
24 });
25 }
26}

Tip given by @Philo01

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord