Great questions! In Laravel, route matching is order-based: Laravel checks routes from top to bottom in your routes file and matches the first one that fits. Static routes (/foo/bar) always take precedence over parameterized routes (/foo/{slug}) if they come first.
Examples:
Route::get('/foo/bar', 'ControllerA');
Route::get('/foo/{slug}', 'ControllerB');
A request to /foo/bar hits ControllerA. If you flip the order, /foo/bar would match the /{slug} route and hit ControllerB.
If you define two parameterized routes like /foo/{id} and /foo/{slug}, the first one wins for any matching URI segment.
Route groups and middleware don't change matching order, but they can affect which controllers and middleware get triggered. For best practices:
- Put static routes before parameterized ones.
- Order from most specific to most general.
- Use
php artisan route:listto double-check.
Gotchas? Watch for duplicate/conflicting parameterized routes—they can be a debugging headache!