Router methods enable the application to respond to any HTTP
request method like the PUT PATCH DELETE
.
The router
method comes in handy. HTTP
methods such as POST
and GET
are the most familiar once we know for basic form submission. We see methods such as PUT
when we deal with API
.
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
any()
methodWhen we build applications, sometimes we want to respond or catch HTTP
requests sent to that route.
Laravel
provides a fluent way to respond to any HTTP
request using the any()
method like this:
Route::any('/', function () {
//
});
The method above will respond to any HTTP
request directed to that uri
.
We might want to filter the HTTP
method that we wish to respond to, so we use the match()
method.
Route::match(['get', 'post'], '/', function () {
//
});
Thus, we specify the HTTP
method we want to respond to.
The route
method is used to catch specific HTTP requests to our application where we don’t want to limit our application to just the GET
and POST
methods.