Laravel Basic | Laravel Routing Tutorial | Laravel 7/6 Route Tutorial

Raviya Technical
3 min readFeb 21, 2022

--

Today, In this tutorial I will explain to you step by step laravel routing tutorial. we will learn how to create a new route in laravel. you can easily create a post route in the laravel application. I will also show how to create routes in the laravel controller.

Let’s see step by step process of how to create the first route in laravel and understanding of laravel routing with the brief.

What is Laravel Routing?

Using Routing you can create a request URL for your application. you can design a set of HTTP requests like POST Request, GET Request, PUT Request and DELETE Request using routing in laravel.

You can easily create a route in the web.php file inside a routes folder. in the web.php file you can create your route list there are several ways. I will show you below step by step how you can create it and how it works, so let’s see step by step explanation.

Create Simple Route:

Here, we will create a very simple route and will let you know how you can access it. so let’s create a simple route using the following line adding in the route file:

routes/web.php

Route::get('simple-route', function () {return 'This is Simple Route Example of raviyatechnical';});

Access URL:

http://localhost:8000/simple-route

Route with Call View File:

You can create a route by directly calling the view blade file from the route directly. You can see below created route example:

routes/web.php

Route::view('my-route', 'index');

resources/views/index.php

<h1>his is Simple Route Example of raviyatechnical</h1>

Access URL:

http://localhost:8000/my-route

Route with Controller Method:

Now, you can create a route with the call controller method so, you can simply create a controller method and call that method with your route as like bellow:

routes/web.php

Route::get('my-route', 'TestController@index');

app/Http/Controllers/TestController.php

<?phpnamespace App\Http\Controllers;class TestController extends Controller{/*** Show the application dashboard.** @return \Illuminate\Contracts\Support\Renderable*/public function index(){return view('index');}}

resources/views/index.php

<h1>his is Simple Route Example of raviyatechnical</h1>

Access URL:

http://localhost:8000/my-route

Create Route with Parameter:

Here, we will create a simple route with passing parameters. you can create a dynamic route with your controller. so let’s create as bellow

routes/web.php

Route::get('users/{id}', 'UserController@show');

app/Http/Controllers/UserController.php

<?phpnamespace App\Http\Controllers;class UserController extends Controller{/*** Show the application dashboard.** @return \Illuminate\Contracts\Support\Renderable*/public function show($id){return 'User ID:'. $id;}}

Access URL:

http://localhost:8000/users/21

Create Route Methods:

You can create get, post, delete, put, patch methods route as bellow i created. you can understand how it works.

So, let’s see below route examples:

Route::get('users', 'UserController@index');Route::post('users', 'UserController@post');Route::put('users/{id}', 'UserController@update');Route::delete('users/{id}', 'UserController@delete');

You can also check how many routes I created using the following command:

php artisan route:list

For Other Tools Routes List Show (Package)

Output like as bellow:

Laravel Basic | Laravel Routing Tutorial | Laravel 7/6 Route Tutorial

You can see the above-created routes.

I hope it can help you…

--

--

No responses yet