Laravel Basic Routing

Laravel Routing Define the flow of the webiste.Routing is one of the essential concepts in Laravel.The purpose of the routes is to route all your application requests to the appropriate controller.Basically Routing defines when and how the things should show in appropriate Manner.

Default Route files

Laravel routes are defined inside the route files located in the routes directory. When we create a project, then a route directory is created inside the project. The route/web.php directory contains the definition of route files for your web interface. The routes in web.php are assigned with the web middleware group that provides the features like session state and CSRF protection. The routes defined in routes/api.php are assigned with the API middleware group, and they are stateless.

The definition of default route files.

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

In the above case, Route is the class which defines the static method get(). The get() method contains the parameters ‘/’ and function() closure. The ‘/’ defines the root directory and function() defines the functionality of the get() method.

 

In the above route, the url is ‘/’; therefore, we entered the http://127.0.0.1:8000 URL in the web browser.

As the method returns the view(‘welcome’), so the above output shows the welcome view of the Laravel.

Another example

Now, we provide another url in this example.

Route::get('/returndata', function ()  
 {      
return "Donec nonummy blanditiis magn!";  
}); 
In the above route, the url is '/returndata'; therefore, we entered the http://127.0.0.1:8000/returndata URL in the web browser.

Leave a Reply

Your email address will not be published. Required fields are marked *