Bird
0
0

You want to create a Laravel route that accepts an optional category and an optional page number, with defaults 'all' and 1 respectively. Which controller method signature correctly supports this?

hard📝 Conceptual Q8 of 15
Laravel - Routing
You want to create a Laravel route that accepts an optional category and an optional page number, with defaults 'all' and 1 respectively. Which controller method signature correctly supports this?
Apublic function list($category = 'all', $page = 1)
Bpublic function list($category, $page = 1)
Cpublic function list($category = 'all', $page)
Dpublic function list($page = 1, $category = 'all')
Step-by-Step Solution
Solution:
  1. Step 1: Understand optional parameters with defaults

    Both parameters are optional and must have default values.
  2. Step 2: Check parameter order and defaults

    Parameters with defaults must come after required ones; here both are optional with defaults.
  3. Final Answer:

    public function list($category = 'all', $page = 1) -> Option A
  4. Quick Check:

    All optional params with defaults in order [OK]
Quick Trick: Set defaults for all optional parameters in order [OK]
Common Mistakes:
  • Omitting default for one optional parameter
  • Placing required param after optional
  • Swapping parameter order incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes