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 = [
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners