Consider this Laravel route definition:
Route::get('/welcome', function () {
return 'Hello GET!';
});What will be the response when a browser sends a GET request to /welcome?
Route::get('/welcome', function () { return 'Hello GET!'; });
Think about what the GET method means in HTTP and how Laravel matches routes.
Laravel matches the GET request to the route and executes the closure, returning the string 'Hello GET!'.
Which of the following route definitions correctly handles POST requests to /submit?
POST requests are used to send data to the server. Which method matches POST?
Only Route::post matches POST HTTP requests. Others match different methods.
Given these routes:
Route::get('/item', function () {
return 'GET item';
});
Route::post('/item', function () {
return 'POST item';
});What happens if a client sends a PUT request to /item?
Route::get('/item', function () { return 'GET item'; }); Route::post('/item', function () { return 'POST item'; });
Check which HTTP methods are defined for the route and what happens if the method is not matched.
Laravel returns 405 when the URL exists but the HTTP method is not supported by any route.
Consider this route:
Route::delete('/post/{id}', function ($id) {
return "Deleted post with ID: $id";
});What will be the response body if a DELETE request is sent to /post/42?
Route::delete('/post/{id}', function ($id) { return "Deleted post with ID: $id"; });
Think about how route parameters work in Laravel and how the DELETE method is matched.
The route matches DELETE requests to /post/{id} and passes the id parameter to the closure, returning the string with the actual id.
In RESTful routing, which HTTP method is conventionally used to partially update an existing resource in Laravel?
PUT replaces the entire resource, but partial updates use a different method.
PATCH is used for partial updates, while PUT replaces the entire resource. POST creates new resources, DELETE removes them.