How to Create Routes in Laravel [Easy Guide]

What is Laravel Route?

In this tutorial I will show an example, You have to write the HTML and PHP code to understand laravel routing. Basically routing help in mapped of routes. 

Routing in Laravel includes the following categories −

  • Basic Routing
  • Route parameters
  • Named Routes

Basic Routing

All routes in laravel application are registered in app/routes.php file. This file describes the application to respond and the particular call. The sample route example for the home page can be seen as given below−

<–route.php–>

Route::get (‘/’, function () {

   return view(‘home ‘);});

<–route.blade.php–>

<–home.blade.php–>

<!DOCTYPE html>

<html>

   <head>

      <title>Laravel Routing</title>

   </head>

   <body>

            <H1>Laravel 7.2 Routing</H1>

   </body>

</html>

<–home.blade.php–>

Route Parameters

Sometimes in the laravel web application, you need to obtain the parameters passed with the requested URL. Todo so, you need to change the code written in above step in routes.php file.

Named Routes

Named routes consist of chaining of more than one routes. The below code shows an example for creating named routes with controller −

Route::get(‘user/route’, ‘RouteController@showRoute’)->name(‘route’);

Final Words

Finally, everything’s done now you basic knowledge of laravel routing. If you face any problem during these tutorials let me know I’m happy to help you to fix that problem. Feel free to comment if any query.

Posted in LaravelTags:

Write a comment