Routing

A route maps an HTTP method and a URI pattern to the code that answers it. Front-Controller Routing sent every request for a missing file to index.php; Laravel 2,157 's router replaces the switch a hand-written front controller would need with declarative routes that capture parameters, load database rows, attach middleware, generate URLs by name, and can be cached for production.

The examples build the bookshop's product, category and order routes on SQLite 4,756 (one migration; Migrations and Seeders teaches migrations). Every response came from php artisan serve --port=8303 and curl 3,008 on Laravel 13.33.0 and PHP 8.5. Lifecycle and Config shows how a request reaches the router, Middleware the middleware routes attach, and Controllers and Responses the controllers they call.

How Laravel's router turns a request into a response
How Laravel's router turns a request into a response

Subsections