By John Koster
patch($uri, $action)
The patch
function is a shortcut to registering a route with the router that responds to the PATCH HTTP verb. The $uri
is the URI of the route, such as /
or login
. The $action
is what will be executed by the router when the route is eventually matched. The $action
can be a Closure
or a mapping to a controller method. Other advanced options exist, but are discussed in more detail in the Routing chapter.
The return value of the patch
function will be an instance \Illuminate\Routing\Route
.
1<?php
2
3// Registering a route with a Closure.
4patch('route-name', function() {
5 // Function logic
6});
7
8// Registering a route mapped to a controller method.
9patch('route-name', 'TestController@someMethod');
The following would produce the same results, but using the Route
façade:
1<?php
2
3// Registering a route with a Closure.
4Route::patch('route-name', function() {
5 // Function logic
6});
7
8// Registering a route mapped to a controller method.
9Route::patch('route-name', 'TestController@someMethod');
The same results can also be accomplished by resolving the router from the application container:
1<?php
2
3// Registering a route with a Closure.
4app('router')->patch('route-name', function() {
5 // Function logic
6});
7
8// Registering a route mapped to a controller method.
9app('router')->patch('route-name', 'TestController@someMethod');
∎