Search

Laravel Router Helper Function: patch

November 21, 2016 —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');

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.