Today now in this blog , I will show you step by step how to create routing in laravel 7/6. Now here i will show how to create a new route in laravel 7/6 application. So now here i will also show how to create route in laravel application controller.
So here i will show step by step process of how to create route in laravel application. Here we know that Routing is one of the best essential concepts in Laravel framework. So Routing in Laravel allows us to route all our application requests to its appropriate controller.
So we know taht in the main and the primary routes in Laravel acknowledge and also it is accept a URI (Uniform Resource Identifier) along also with a closure, so given that it should have to be a simple and also expressive way of routing.
What is Laravel Routing?
By Using Routing we can create a request to URL for our application. So here we can design a set of HTTP request as like as POST, GET Request, PUT and also DELETE Request by using the routing in laravel.
So here I will describe with you bellow step by step how we can create it and how it works, so let’s start and see step by step explanation.
Create Simple Route
Now here ,i will create a very simple route and also will let you know how we can access it. So let’s create simple route by using following line adding in our route file:
following path:/routes/web.php
Route::get('simple-route-example', function () { return 'This is Simple Route Example of Nicesnippets.com'; });
Access Url
http://localhost:8000/simple-route-example
Route with Call View File
So now,we can also create route with directly to call view blade file from route directly.
following path:/routes/web.php
Route::view('call-view-route', 'index');
following path:/resources/views/index.blade.php
<h1>His Is Call View Route Example of Nicesnippets.com</h1>
Access Url
http://localhost:8000/call-view-route
Route with Controller Method
Now here,we can also create route with call controller method so, we can simply create controller method and it call that method with our route as like bellow
following path:/routes/web.php
Route::get('route-with-controller', 'MainController@index')
following path:/app/Http/Controllers/MainController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class MainController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { return view('index'); } }
following path:/resources/views/index.php
<h1>His Is Route with Controller Method Example of Nicesnippets.com</h1>
Access Url
http://localhost:8000/route-with-controller
Create Route with Parameter
So now, I will create a simple route also with passing parameters. we can create dynamic route with our controller.
following path:/routes/web.php
Route::get('route-with-parameter/{$name}', 'ClientController@show')
following path:/app/Http/Controllers/MainController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ClientController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function show($name) { return 'Client Name:'. $name; } }
Access Url
http://localhost:8000/route-with-parameter/nicesnippets
Create Route Methods
Now here, i will create get, post, delete, put, patch methods route as bellow i created. so we can understand how it works.
so, let’s see here route examples:
Route::get('players', 'PlayerController@index'); Route::post('players', 'PlayerController@post'); Route::put('players/{id}', 'PlayerController@update'); Route::delete('players/{id}', 'PlayerController@delete');
Get Route List in Command Prompt
Now here i will show all route list in command prompt. so you can also check that how many routes you are created by using following command
php artisan route:list
Read Also : Laravel Pagination with Ajax Example
Thank you read.Hope it will help you. Also follow on facebook