Route Parameters and Named Routes
Real applications rarely have only static URLs — a blog needs a route per post, a shop needs a route per product. Laravel handles this through route parameters, and it lets developers reference routes by name instead of hardcoding URLs everywhere.
Route Parameters
A route parameter is a placeholder in the URL pattern that captures part of the request and passes it into the controller or closure. Parameters can be required or optional, and Laravel supports constraining them with regular expressions when needed.
Named Routes
Rather than typing out full URLs throughout an application, Laravel lets you assign a name to a route and generate links or redirects using that name instead. If the underlying URL ever changes, every reference automatically updates, since nothing depends on the literal path.
| Syntax | Example |
|---|---|
| Required parameter | Route::get('/post/{id}', ...) |
| Optional parameter | Route::get('/post/{id?}', ...) |
| Naming a route | Route::get('/post/{id}', ...)->name('post.show') |
| Generating a URL from a name | route('post.show', ['id' => 1]) |
Why This Matters
- Keeps URLs flexible without duplicating route logic for every possible value
- Prevents broken links when a URL structure changes later
- Makes navigation code in views and controllers easier to read
Routes work well for small amounts of logic, but as an application grows, that logic needs a proper home — which is exactly the role controllers play.
Ready to master Laravel Training Course?
Join Uncodemy's hands-on Laravel program and build real, production-ready applications.
