Recently I came across a unique approach to loading routes into Laravel applications, and I wanted to share this with you. It allows you to create Route Registrars classes you register your routes within.
We make a few changes to the Route Service Provider - and remove the web and API route files.
{ $registrar->view('/', 'welcome'); Now that our default registrar is created, we can register this inside our Route Service Provider, ensuring it is loaded.
As an example, I would imagine the route service provider looking like the following: declare(strict_types=1); namespace App\Providers; use App\Routing\Concerns\MapsRouteRegistrars; use App\Routing\Registrars\AdminRegistrar; use App\Routing\Registrars\BlogRegistrar; use App\Routing\Registrars\MarketingRegistrar; use Illuminate\Contracts\Routing\Registrar; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; class RouteServiceProvider extends ServiceProvider { use MapsRouteRegistrars; protected array $registrars = [