Laravel Routing Tutorial | Laravel 7/6 Route Tutorial

Laravel Routing Tutorial | Laravel 7/6 Route Tutorial

In this post we will give you information about Laravel Routing Tutorial | Laravel 7/6 Route Tutorial. Hear we will give you detail about Laravel Routing Tutorial | Laravel 7/6 Route TutorialAnd how to use it also give you demo for it if it is necessary.

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

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

I also posted how to install laravel, so if you don’t know how to install laravel project then follow this article Install Laravel Step By Step.

What is Laravel Routing?

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

You can easily create route in web.php file inside a routes folder. in web.php file you can create your route list there are several ways. i will show you bellow 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 very simple route and will let you know how you can access it. so let’s create simple route using following line adding in route file:

routes/web.php

Route::get('simple-route', function () {

return 'This is Simple Route Example of ItSolutionStuff.com';

});

Access URL:

http://localhost:8000/simple-route

Route with Call View File:

You can create route with directly call view blade file from route directly. You can see bellow created route example:

routes/web.php

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

resources/views/index.php

<h1>his is Simple Route Example of ItSolutionStuff.com</h1>

Access URL:

http://localhost:8000/my-route

Route with Controller Method:

Now, you can create route with call controller method so, you can simply create 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

<?php

namespace AppHttpControllers;

class TestController extends Controller

{

/**

* Show the application dashboard.

*

* @return IlluminateContractsSupportRenderable

*/

public function index()

{

return view('index');

}

}

resources/views/index.php

<h1>his is Simple Route Example of ItSolutionStuff.com</h1>

Access URL:

http://localhost:8000/my-route

Create Route with Parameter:

Here, we will create simple route with passing parameters. you can can create 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

<?php

namespace AppHttpControllers;

class UserController extends Controller

{

/**

* Show the application dashboard.

*

* @return IlluminateContractsSupportRenderable

*/

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 bellow 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 following command:

Also see:Laravel 7/6 User Roles and Permissions from Scratch | Laravel 7/6 ACL

php artisan route:list

Output like as bellow:

You can see above created routes.

You can also create resource routes as i written tutorial on it. You can see here: Create Resource Routes in Laravel.

I hope it can help you…

Hope this code and post will helped you for implement Laravel Routing Tutorial | Laravel 7/6 Route Tutorial. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

79  +    =  80

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US