Laravel routes are very simple, they keep your project neatly organized. The routes are usually the best place to look to understand an application is linked together.
The Laravel documentation on routing is very elaborate.
The example you sited is an example of a GET route to the /
URL.
It accepts a callback as a second parameter. This callback determines how the request is processed. In this case, a view response is returned.
Route::get('/', function () {
return view('welcome');
});
There are different types of routes:
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
You can also pass parameters through your routes:
You may define as many route parameters as required by your route:
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
// });
Sometimes you may need to register a route that responds to multiple
HTTP verbs. You may do so using the match method. Or, you may even
register a route that responds to all HTTP verbs using the any method:
Route::match(['get', 'post'], '/', function () {
//
});
Route::any('foo', function () {
//
});
Here is a good piece on the subject.