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
November 04 2025
How to Install Composer for Ubuntu and Windows Step-by-Step GuideIn this post you can learn how to easily install Composer on both Ubuntu and Windows with this detailed step-by-step guide.
December 01 2025
DNS Checker Tool - Verify Your DNS Records and IP AddressIf you're managing a website, ensuring that your DNS records are correctly configured is crucial for maintaining its performance and availability. With our DNS Checker Tool, you can easily verify your DNS records and check your IP address to troubleshoot any issues that may arise.
November 03 2025
Laravel Installation on Ubuntu with Nginx – Complete Configuration GuideLaravel is the ultimate free and open-source PHP framework designed for building fast, secure, and reliable web applications. It has quickly become the industry standard thanks to its powerful, cohesive toolset that guarantees a streamlined development process for any modern PHP project.
© 2026 — Revision. All Rights Reserved.