6.7. Creating Controllers and Configuring Routing
The Laravel framework has a powerful routing subsystem. You can display your routes both for simple callback functions and for the controller methods. The simplest sample routes look like this:
Route::get('/', function () {
return 'Hello World';
});
Route::post('foo/bar', function () {
return 'Hello World';
});
In the first example, we register the handler of the GET request for the website root for the POST request with the route /foo/bar
in the second.
You can register a route for several types of HTTP requests. For example:
Route::match(['get', 'post'], 'foo/bar', function () {
return 'Hello World';
});
You can extract some part of the URL from the route for use as a parameter in the handling function:
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
//
});
The parameters of a route are always enclosed in braces.
You can find more details about routing configuration in the Routing chapter of the documentation. Routes are configured in the app/Http/routes.php
file in Laravel 5.2 and in the routes/wep.php
file in Laravel 5.3.