November 21, 2016 —John Koster
get($uri, $action)
The get
function is a shortcut to registering a route with the router that responds to the GET 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 get
function will be an instance \Illuminate\Routing\Route
.
1<?php2 3// Registering a route with a Closure.4get('/', function() {5 return view('welcome'):6});7 8// Registering a route mapped to a controller method.9get('/', 'TestController@sayHello');
The following would produce the same results, but using the Route
façade:
1<?php2 3// Registering a route with a Closure.4Route::get('/', function() {5 return view('welcome'):6});7 8// Registering a route mapped to a controller method.9Route::get('/', 'TestController@sayHello');
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')->get('/', function() {5 return view('welcome'):6});7 8// Registering a route mapped to a controller method.9app('router')->get('/', 'TestController@sayHello');
∎
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.