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.
November 10 2025
Getting Started with Laravel 12 Starter Kits (React/Vue/Livewire)Discover how to kickstart your Laravel 12 projects with the most popular starter kits—React, Vue, and Livewire. Step-by-step guidance for setting up, configuring, and building your first app efficiently.
November 10 2025
Laravel 12 – Fixing storage:link Asset ErrorFacing the “storage:link” asset error in Laravel 12? This guide walks you through the exact fixes for missing symlinks, incorrect file paths, and permission issues. Learn how to reconnect your public/storage link, adjust filesystem settings, and make uploaded files publicly accessible on both VPS and shared hosting environments.
© 2025 — Revision. All Rights Reserved.