Bird
0
0

How would you define a route that responds to both GET and POST requests at '/submit' using a single route definition?

hard📝 Application Q9 of 15
Laravel - Routing
How would you define a route that responds to both GET and POST requests at '/submit' using a single route definition?
ARoute::match(['get', 'post'], '/submit', function () { return 'Submitted'; });
BRoute::get('/submit', function () { return 'Submitted'; }); Route::post('/submit', function () { return 'Submitted'; });
CRoute::any('/submit', function () { return 'Submitted'; });
DRoute::post('/submit', function () { return 'Submitted'; });
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to handle multiple HTTP methods in one route

    Laravel's Route::match() accepts an array of methods to handle multiple HTTP verbs.
  2. Step 2: Check the syntax for matching GET and POST

    Using Route::match(['get', 'post'], '/submit', ...) correctly handles both methods in one route.
  3. Final Answer:

    Route::match(['get', 'post'], '/submit', function () { return 'Submitted'; }); -> Option A
  4. Quick Check:

    Route::match handles multiple methods in one route [OK]
Quick Trick: Use Route::match() for multiple HTTP methods [OK]
Common Mistakes:
  • Defining separate routes instead of one
  • Using Route::any() which allows all methods
  • Using only Route::post or Route::get

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes