Skip to the workspace
Pebellslearn by building
Request–Response Flow and Project Folders  ›  Lesson

The Request–Response Flow

Request–Response Flow 12 minEvery request enters through public/index.php, the app is built from bootstrap/app.php, passes through middleware to the router and a controller, and the response travels back out through the same middleware.

laravel / The Request–Response Flow

Explore each scene at your own pace.

01 · The rule

The rule

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:

  1. public/index.php: the web server sends every request here. It is the only PHP file the outside world can reach.
  2. bootstrap/app.php: index.php loads Composer's autoloader, then asks this file to build the application. This is where routing files, middleware and exception handling are configured.
  3. Boot: Laravel loads configuration, sets up error handling and runs the service providers, which register the app's pieces.
  4. 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.
  5. 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.
  6. Response: whatever the controller returns, whether a view, JSON or a redirect, is turned into a response object.
  7. Back out: the response passes back through the same middleware in reverse, then index.php sends 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();
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.