Unable to locate the api.php route file in Laravel 11

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Integrating Laravel 11 with React.js: No More api.php File? Body:

The recent release of Laravel 11 brought several exciting new features and improvements, making it easier than ever to develop elegant web applications. However, as you attempt to combine Laravel 11 with React.js for a seamless data flow between the two technologies, you might be struggling to locate the traditional routes/api.php file that once served as the gateway for API routes.

One of the major changes in Laravel 11 is the removal of the default web, api, and auth middleware groups. These groups previously governed the access to different route files, with api.php being an essential file for handling all API routes. However, this has changed in Laravel 11 - you will no longer find the routes/api.php file as the designated location for defining your API routes.

The reason behind this change is to promote the inclusion of more fine-grained authorization rules using the newly introduced Gate class and middleware groups. This approach makes it possible for developers to define customized groups with specific permissions, ensuring only authorized users have access to designated routes.

With this new approach, the old routes/api.php file should be replaced by a more granular implementation that uses middleware groups and authorization rules. To begin setting up your API routes in Laravel 11, follow these steps:

  1. Create a new middleware group for your API endpoints by adding the following code to /app/Http/Kernel.php:
  2.  // app/Http/Kernel.php
    <protected array $middlewareGroups = [
        `...>, // Default group
        `api>{`web>}, // Web middleware group
        `api>{`auth>}, // Auth middleware group
        `api>{`api>}, // API middleware group
    ];
  3. Define a new route collection for your custom API routes in the /config/routes.php file. Replace the old api.php route file content with the following:
  4.  // config/routes.php
    <Route::middleware('api')
        {`get, head>{`web>}, // All web-based requests
        {`auth>{`api>}, // Authenticated API routes
        {
            `prefix>'/v1/';
            `route(:'{get|post}', ':controller.(:action)')
                <Route::get('/:controller', 'App\\Http\\Controllers\\Controller@index')->where('controller', '(?P<controller>[a-zA-Z-]+)[/.w]');
                <Route::post('/:controller/{action}', 'App\\Http\\Controllers\\ActionController@store')
                    <Route::get('/:controller/:id', 'App\\Models\\Model@show');
            >}
        },`api>{`auth>}, // Authenticated API routes
        {`prefix>'/v1/';
            `route(:'{get|post}', ':controller.(:action)')
                <Route::get('/:controller', 'App\\Http\\Controllers\\Controller@index')->where('controller', '(?P<controller>[a-zA-Z-]+)[/.w]');
                <Route::post('/:controller/{action}', 'App\\Http\\Controllers\\ActionController@store')
                    <Route::get('/:controller/:id', 'App\\Models\\Model@show');
            >}
    </Route>
  5. Create your custom API routes by following the route definitions and adding appropriate middleware groups for each route.

As you can see, Laravel 11 has changed the way we handle API routes. Instead of using a specific file like before, it promotes customization through middleware groups and granular authorization rules. This new approach allows for more control over your application's security, making Laravel 11 even more robust and flexible than ever.

Conclusion: Integrating Laravel 11 with React.js has become an exciting opportunity for developers looking to leverage the power of both technologies. While it may seem daunting at first, following these steps will help you effectively implement customized API routes and enable efficient data exchange between Laravel 11's backend and your frontend application built using React.js.

 

Read the Complete Blog Post