beginnerLaravel
What are optional route parameters?
Answer
Clear, interview-ready explanation
An optional route parameter is written with a question mark after its name, such as /users/{name?}. It allows the route to match whether that segment is present or absent.
The corresponding closure or controller argument should have a default value or allow null, for example function (?string $name = null). Optional parameters are best used when the URI still has an unambiguous meaning; separate routes are often clearer when optional segments would make routing hard to understand or conflict with other routes.