November 21, 2016 —John Koster
put($uri, $action)
The put
function is a shortcut to registering a route with the router that responds to the PUT 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 put
function will be an instance \Illuminate\Routing\Route
.
1<?php2 3// Registering a route with a Closure.4put('route-name', function() {5 // Function logic6});7 8// Registering a route mapped to a controller method.9put('route-name', 'TestController@someMethod');
The following would produce the same results, but using the Route
façade:
1<?php2 3// Registering a route with a Closure.4Route::put('route-name', function() {5 // Function logic6});7 8// Registering a route mapped to a controller method.9Route::put('route-name', 'TestController@someMethod');
The same results can also be accomplished by resolving the router from the application container:
1<?php2 3// Registering a route with a Closure.4app('router')->put('route-name', function() {5 // Function logic6});7 8// Registering a route mapped to a controller method.9app('router')->put('route-name', 'TestController@someMethod');
∎
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.