Muhammad Manamil on November 10, 2025
Laravel 12 has simplified how applications are bootstrapped and routes are registered.
Instead of the traditional routes/web.php and routes/api.php being loaded automatically through RouteServiceProvider, Laravel 12 gives developers more control by defining routes directly in the bootstrap/app.php file.
This new approach makes the app startup process faster, cleaner, and easier to customize — especially for microservices or lightweight Laravel setups.
Before Laravel 12, your routes were usually registered through the RouteServiceProvider:
// In routes/web.php
Route::get('/', function () {
return view('welcome');
});
Laravel automatically loaded these files via the provider.
But from Laravel 12 onward, you can define routes directly inside bootstrap/app.php using the new closure-based bootstrapping style.
bootstrap/app.php StructureA typical bootstrap/app.php file in Laravel 12 looks like this:
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
// Register your middleware
})
->withExceptions(function (Exceptions $exceptions) {
// Handle custom exceptions
})
->create();
But now, you can define routes right inside this file using closures.
bootstrap/app.phpExample of defining a route inline without creating web.php:
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Application;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
using: function () {
Route::get('/', function () {
return 'Welcome to Laravel 12!';
});
Route::get('/about', function () {
return 'This is the about page.';
});
Route::get('/contact', function () {
return 'Contact us at support@example.com';
});
}
)
->create();
This method:
Removes the need for extra routes/web.php or RouteServiceProvider.
Speeds up boot time.
Keeps configuration and routes in one place — perfect for small or API-only apps.
If you still want to keep traditional route files, you can mix both approaches:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
using: function () {
Route::get('/', fn() => 'Home Page');
},
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php'
)
->create();
This gives you flexibility: define quick routes inline and load complex ones from files.
Taylor Otwell introduced this cleaner structure for several reasons:
Performance: Fewer service providers to boot.
Clarity: All core app configuration lives in one file.
Flexibility: Ideal for small services or when you want to customize how routes are loaded.
Forgetting to import Route:
Always add use Illuminate\Support\Facades\Route; at the top.
Misplacing closure syntax:
The closure for using: must be properly enclosed.
Missing trailing commas or parentheses can break your configuration chain.
Mixing route groups incorrectly — wrap them properly if using middleware.
Example:
Route::middleware('auth')->group(function () {
Route::get('/dashboard', fn() => 'Dashboard');
});
bootstrap/app.phpYou can also define API routes like this:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
using: function () {
Route::prefix('api')->group(function () {
Route::get('/users', fn() => ['user' => 'John Doe']);
Route::post('/login', fn() => ['message' => 'Login success']);
});
}
)
->create();
This makes it super easy to build simple APIs without needing the full Laravel directory structure.
Laravel 12 brings a fresh, modern approach to routing by allowing routes to be defined right in bootstrap/app.php.
This update simplifies project setup, improves flexibility, and makes Laravel more modular — especially useful for microservices and small apps.
Whether you define routes inline or in separate files, Laravel 12 ensures smooth routing management with better control.
Yes, Laravel 12 still supports traditional route files. You can use both inline routes in bootstrap/app.php and external route files simultaneously.
The goal is to simplify application bootstrapping and improve performance by reducing provider overhead and centralizing configuration.
No. It’s optional. You can keep using routes/web.php and routes/api.php if you prefer the classic structure.
No. Older versions will keep using the previous structure. This change applies only if you upgrade to Laravel 12 and adopt the new setup.
Absolutely. Middleware, groups, and route parameters work exactly as before. Just make sure to import the Route facade properly.
Featured Posts
Categories
December 01 2025
How to Check Your Domain's IP Address | Easy Step-by-Step GuideLearn how to quickly check the IP address of your domain using methods for Ubuntu, Mac, and online DNS tools. Whether you're troubleshooting, securing your website, or configuring DNS settings, this guide provides simple, actionable steps to find your domain's IP with ease.
November 26 2025
DNS Checker Guide: Tools, Online Services, and Email CheckDiscover the best DNS checker tools and online services for Google DNS, global DNS, website DNS, email DNS, and more. Learn how to check IPs, reverse lookup, blacklists, and email headers with ease
January 19 2026
Unmasking the N+1 Query Problem in Laravel: Your Guide to Faster AppsStop the N+1 query problem from killing your Laravel app's performance! 🚀 Learn exactly what causes this common database bottleneck and how to fix it in seconds using Eloquent Eager Loading (with()). Perfect for beginners looking to write professional, lightning-fast code.
© 2026 — Revision. All Rights Reserved.