Complete the code to define a route with an optional parameter named 'id'.
Route::get('/user/{id[1]', function ($id = null) { return $id ? "User ID: $id" : 'No ID provided'; });
In Laravel, optional route parameters are marked with a question mark ? after the parameter name.
Complete the controller method signature to make the parameter 'page' optional with a default value of 1.
public function showPage([1] $page = 1) { return "Showing page: $page"; }
The parameter type int matches the expected page number and allows a default value.
Fix the error in the route definition by correctly marking the 'category' parameter as optional.
Route::get('/products/{category[1]', function ($category = 'all') { return "Category: $category"; });
The question mark ? after the parameter name makes it optional in Laravel routes.
Fill both blanks to define a route with an optional 'slug' parameter and a default value in the closure.
Route::get('/post/{slug[1]', function ($slug [2] 'default-post') { return "Post slug: $slug"; });
The question mark ? marks the parameter optional in the route, and the equals sign = sets the default value in the closure.
Fill all three blanks to create a controller method with an optional string parameter 'name' defaulting to 'Guest' and return a greeting.
public function greet([1] $name [2] 'Guest') { return "Hello, [3]!"; }
The parameter is typed as string, given a default value with =, and the variable $name is used in the return string.