By John Koster
post($uri, $action)
The post
function is a shortcut to registering a route with the router that responds to the POST 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 post
function will be an instance \Illuminate\Routing\Route
.
1<?php
2
3// Registering a route with a Closure.
4post('login', function() {
5 // Login implementation
6});
7
8// Registering a route mapped to a controller method.
9post('login', 'TestController@sayHello');
The following would produce the same results, but using the Route
façade:
1<?php
2
3// Registering a route with a Closure.
4Route::post('login', function() {
5 // Login implementation
6});
7
8// Registering a route mapped to a controller method.
9Route::post('login', 'TestController@doLogin');
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')->post('login', function() {
5 // Login implementation
6});
7
8// Registering a route mapped to a controller method.
9app('router')->post('login', 'TestController@doLogin');
∎