Web Developer

In Laravel, all requests are mapped with the help of routes. Basic routing routes the request to the associated controllers. This chapter discusses routing in Laravel.

Routing in Laravel includes the following categories: Basic Routing - Route parameters - Named Routes

Basic Routing: All the application routes are registered within the app/routes.php file. This file tells Laravel for the URIs it should respond to and the associated controller will give it a particular call. The sample route for the welcome page can be seen as shown in the screenshot given below.

Route::get ('/', function () { 
  return view('welcome');
});

Route Parameters: These parameters are those which should be mandatorily captured for routing the web application. For example, it is important to capture the user’s identification number from the URL. This can be possible by defining route parameters as shown below.

Route::get('user/{id}',function($id) {
   echo 'User: '.$id;
});

Named routes: allow a convenient way of creating routes. The chaining of routes can be specified using name method onto the route definition. The following code shows an example for creating named routes with controller

Route::get('user/profile', 'UserController@profile')->name('profile');