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:
Step 1: Identify HTTP methods for form pages
The form page is shown with GET (to display), and submission uses POST (to send data).
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.
Final Answer:
Route::get('/form', function () { return view('form'); }); Route::post('/submit', function () { return 'Form submitted'; }); -> Option A
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
Master "Routing" in Laravel
9 interactive learning modes - each teaches the same concept differently