routes/api.php is missing in Laravel 12: how to add it?

laravel
tutorial
routes
Nabil Hassen
Nabil Hassen
Aug 27, 2025
How to Fix Missing API Routes File in Laravel 12
Last updated on Nov 6, 2025
Table of contents:

Understanding API Routes in Laravel 12

If you’re building an API with Laravel 12 and notice that the familiar routes/api.php file is missing, you’re not alone. Starting with Laravel 11, the framework no longer includes the API routes file by default.

This guide explains why the file was removed, how to correctly restore it, and the best practices for structuring and securing your API routes in Laravel 12.

Why Laravel Removed api.php by Default

Laravel’s design philosophy emphasizes simplicity and minimalism. Since not every application requires an API, the core team decided to exclude the api.php file from new installations starting in Laravel 11.

This change helps keep new projects lightweight. When you do need to build APIs, Laravel provides an explicit installation process to add the required routes and middleware.

How to Add the API Routes File in Laravel 12

To add the API routes setup, run the following Artisan command:

php artisan install:api

This command generates a new routes/api.php file and registers it in the application’s routing configuration. After running it, you can define your API routes exactly as in previous Laravel versions.

Example:

use Illuminate\Support\Facades\Route;
 
Route::get('/users', function () {
return [
'name' => 'John Doe',
'email' => '[email protected]',
];
});

Now, visiting /api/users in your browser or API client returns the JSON response.

If you forget to run php artisan install:api, any references to API routes will result in a “route not found” related errors.

Common Issues and Fixes

1. api.php file not found: Run php artisan install:api to recreate the missing file.

2. Route returns 404: Check that your route is defined under the correct prefix (/api/...). Laravel automatically prefixes all API routes with /api.

Conclusion

If your Laravel 12 project doesn’t include routes/api.php, that’s intentional. The file was removed to keep the framework minimal. When you need it, simply run:

php artisan install:api

With this command, you restore full API scaffolding and can begin building secure, versioned, and efficient endpoints immediately.

Laravel’s new modular approach ensures projects stay lean while still providing everything you need for robust API development.

Nabil Hassen
Nabil Hassen
Full Stack Web Developer

Stay Updated.

I'll you email you as soon as new, fresh content is published.

Thanks for subscribing to my blog.

Latest Posts