Recall & Review
beginner
What is a route parameter in Laravel?
A route parameter is a placeholder in a URL that captures dynamic values from the URL and passes them to the controller or closure handling the route.
Click to reveal answer
beginner
How do you define a required route parameter in Laravel?
You define a required route parameter by placing curly braces around the parameter name in the route URI, like
/user/{id}. This means the URL must include a value for id.Click to reveal answer
beginner
What happens if you visit a Laravel route with a missing required parameter?
Laravel will return a 404 Not Found error because the route expects a parameter value and it was not provided in the URL.
Click to reveal answer
intermediate
How do you define an optional route parameter in Laravel?
You add a question mark after the parameter name inside the braces, like
/user/{name?}. You should also provide a default value in the controller or closure to handle when the parameter is missing.Click to reveal answer
intermediate
How can you restrict a route parameter to only accept numbers in Laravel?
You use the
where method on the route to add a regular expression constraint, for example: Route::get('/user/{id}', ...)->where('id', '[0-9]+'); This ensures only numeric values are accepted.Click to reveal answer
How do you define a required route parameter in Laravel?
✗ Incorrect
Required route parameters are defined with curly braces like /user/{id}.
What symbol makes a route parameter optional in Laravel?
✗ Incorrect
Adding a question mark after the parameter name makes it optional, e.g., {name?}.
What happens if you visit a route missing a required parameter?
✗ Incorrect
Missing required parameters cause Laravel to return a 404 error.
How do you restrict a route parameter to only numbers?
✗ Incorrect
The where method with a regex like '[0-9]+' restricts the parameter to numbers.
Which of these is a valid route with an optional parameter?
✗ Incorrect
Optional parameters use a question mark inside curly braces: {id?}.
Explain how to create a Laravel route with a required parameter and how Laravel handles the parameter value.
Think about how URLs can carry dynamic info.
You got /4 concepts.
Describe how to make a route parameter optional and how to handle it in the controller.
Optional means it can be there or not.
You got /3 concepts.