Bird
0
0

Which of the following is the correct syntax to retrieve the 'category' query parameter in a Laravel controller method?

easy📝 Syntax Q3 of 15
Laravel - Request and Response
Which of the following is the correct syntax to retrieve the 'category' query parameter in a Laravel controller method?
A$category = $request->query('category');
B$category = $request->getQuery('category');
C$category = $request->inputQuery('category');
D$category = $request->params('category');
Step-by-Step Solution
Solution:
  1. Step 1: Recall Laravel request query syntax

    The query() method is the standard way to get query parameters from the request object.
  2. Step 2: Verify method names

    Methods like getQuery(), inputQuery(), and params() do not exist in Laravel's request class.
  3. Final Answer:

    $category = $request->query('category'); -> Option A
  4. Quick Check:

    Correct query param syntax = $request->query('key') [OK]
Quick Trick: Use $request->query('param') to get query parameters [OK]
Common Mistakes:
  • Using non-existent methods like getQuery()
  • Confusing input() with query()
  • Trying to use params() which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes