Routing is one of the essential concepts in Laravel. Routing in Laravel allows you to route all your application requests to their appropriate controller. The main and primary routes in Laravel acknowledge and accept a URI (Uniform Resource Identifier)
Creating routes in laravel
All the routes in Laravel are defined within the route files you can find in the routes sub-directory. These route files get loaded and generated automatically by the Laravel framework. The application’s route file gets defined in the app/Http/routes.php file.
Example
<?php
Route:: get ('/', function () {
return view('laravel');
});
The routing mechanism in laravel
- First of all, you have to create and run the root URL of your project.
- The URL you run needs to be matched exactly with your method defined in the root.php file, and it will execute all related functions.
- The function invokes the template files. It then calls the view() function with the file name located in resources/views/, and eliminates the file extension blade.php at the time of calling.
Routes parameters
Laravel provides two ways of capturing the passed parameter:
- Required parameter
- Optional Parameter