The Request–Response Flow
A member opens http://lendly.test/books, and a list of books appears. Between those two moments, Laravel runs the request through a fixed series of stops. Once you know the order, every file you meet later has a place: "this runs before routing", "this runs inside the controller".
The rule
One door in, middleware around, router in the middle, same way out.
Follow the request:
public/index.php: the web server sends every request here. It is the only PHP file the outside world can reach.bootstrap/app.php:index.phploads Composer's autoloader, then asks this file to build the application. This is where routing files, middleware and exception handling are configured.- Boot: Laravel loads configuration, sets up error handling and runs the service providers, which register the app's pieces.
- Global middleware: layers that every request passes through, such as trimming whitespace from input or showing a "back soon" page while the site is in maintenance mode.
- Router: matches the method and path against
routes/web.php, runs that route's own middleware, such as sessions and CSRF protection, then calls the closure or controller. - Response: whatever the controller returns, whether a view, JSON or a redirect, is turned into a response object.
- Back out: the response passes back through the same middleware in reverse, then
index.phpsends it to the browser.
In Laravel 11 and 12, bootstrap/app.php is short and readable:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();