Bird
0
0

You want to create two routes: one for showing a form at '/form' and one for processing the form submission at '/submit'. Which routing setup correctly maps URLs to logic in Laravel?

hard📝 state output Q15 of 15
Laravel - Routing
You want to create two routes: one for showing a form at '/form' and one for processing the form submission at '/submit'. Which routing setup correctly maps URLs to logic in Laravel?
ARoute::get('/form', function () { return view('form'); });\nRoute::post('/submit', function () { return 'Form submitted'; });
BRoute::post('/form', function () { return view('form'); });\nRoute::get('/submit', function () { return 'Form submitted'; });
CRoute::get('/submit', function () { return view('form'); });\nRoute::post('/form', function () { return 'Form submitted'; });
DRoute::get('/form', function () { return 'Form submitted'; });\nRoute::post('/submit', function () { return view('form'); });
Step-by-Step Solution
Solution:
  1. Step 1: Identify HTTP methods for form pages

    The form page is shown with GET (to display), and submission uses POST (to send data).
  2. Step 2: Match routes to URLs and methods

    Route::get('/form', function () { return view('form'); });\nRoute::post('/submit', function () { return 'Form submitted'; }); correctly uses Route::get for '/form' to show the form view, and Route::post for '/submit' to handle submission.
  3. Final Answer:

    Route::get('/form', function () { return view('form'); }); Route::post('/submit', function () { return 'Form submitted'; }); -> Option A
  4. Quick Check:

    GET shows form, POST submits form [OK]
Quick Trick: Use GET for showing forms, POST for submitting forms [OK]
Common Mistakes:
  • Using POST to show form page
  • Using GET to submit form data
  • Mixing URLs and HTTP methods incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes