« back published by @mmartin_joo on April 24, 2024

Laravel 11 RouteServiceProvider

In Laravel 11, the RouteServiceProvider.php file is removed. So the question is how can we configure the routes?

Let's say we want to add API routes with a prefix of /api. In previous Laravel versions this was done in the RouteServiceProvider.php file:

public function boot()
  $this->routes(function () {

Now in Laravel 11, we need to use the bootstrap/app.php file again:

return Application::configure(basePath: dirname(__DIR__))
    web: __DIR__.'/../routes/web.php',
    api: __DIR__.'/../routes/api.php',
    commands: __DIR__.'/../routes/console.php',
    health: '/up',
    apiPrefix: '/api',

We can check if it works by running the php artisan route:list command:

Laravel 11

If you want learn about all Laravel 11 updates, check out this article