0
0
Laravelframework~10 mins

Basic route definition in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a GET route for the home page that returns a view.

Laravel
Route::[1]('/', function () {
    return view('welcome');
});
Drag options to blanks, or click blank then click option'
Aput
Bpost
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using post instead of get for a page load route.
Using put or delete which are for updating or deleting data.
2fill in blank
medium

Complete the code to define a POST route for submitting a form to '/submit'.

Laravel
Route::[1]('/submit', function () {
    // handle form submission
});
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cpatch
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of post for form submission routes.
Using patch or delete which are for updating or deleting resources.
3fill in blank
hard

Fix the error in the route definition to correctly define a route that responds to any HTTP method for '/any'.

Laravel
Route::[1]('/any', function () {
    return 'Any method';
});
Drag options to blanks, or click blank then click option'
Aany
Bget
Cmatch
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using get or post which only respond to one HTTP method.
Using match without specifying methods.
4fill in blank
hard

Fill both blanks to define a route that matches only GET and POST methods for '/submit'.

Laravel
Route::[1](['get', '[2]'], '/submit', function () {
    return 'Submit form';
});
Drag options to blanks, or click blank then click option'
Amatch
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using get or post alone instead of match for multiple methods.
Including methods other than get or post.
5fill in blank
hard

Fill all three blanks to define a route that responds to PUT requests on '/update' and uses the 'update' method of 'UserController'.

Laravel
Route::[1]('/update', [[2]::class, '[3]']);
Drag options to blanks, or click blank then click option'
Aput
BUserController
Cupdate
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using post instead of put for update routes.
Not specifying the controller class or method correctly.