In Laravel, you can define a route that responds to multiple HTTP methods by using the match
method or by explicitly defining multiple routes for each HTTP method.
match
method:use Illuminate\Support\Facades\Route;
Route::match(['get', 'post'], '/example', function () {
// Your code here
});
In this example, the route /example
will respond to both GET
and POST
HTTP methods.
use Illuminate\Support\Facades\Route;
Route::get('/example', function () {
// Your code here for GET method
});
Route::post('/example', function () {
// Your code here for POST method
});
In this example, we have defined two separate routes for the same URL /example
. The first route will respond to GET
method, and the second route will respond to POST
method.
You can use any of these methods based on your requirement. Remember to replace the placeholder code with your actual logic for handling the HTTP methods.