I'll give you a step-by-step instruction on laravel routing in this blog. We'll demonstrate how to make a new route in Laravel and how to make a route in Laravel's controller.

We'll outline a step-by-step procedure for creating routes in Laravel. One of the fundamental ideas in Laravel is routing. You may direct all of your application's requests to the proper controller using Laravel's routing feature.

Given that a URI (Uniform Resource Identifier) and closure must be a straightforward and expressive method of routing, Laravel's main and primary routes recognize and accept URIs.

Create Simple Route

Here, I'll develop a very basic route and explain how to access ISO. Let's start by creating a basic route by adding the following line to the route file:

/routes/web.php

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

Access URL - 

http://localhost:8000/simple-route-example

Route with Call View File

Now, we can establish a route by calling the view blade file directly from the route.

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

/resources/views/index.php

<h1>His Is Call View Route Example of codesolutionstuff.com</h1>

Access URL -

http://localhost:8000/call-view-route

Route with Controller Method

Here, you have the option to construct a route that calls a controller method, so you can do so by creating a controller method and calling it from your route as seen below.

/routes/web.php

Route::get('route-with-controller', 'MainController@index')

/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');
    }
 }

/resources/views/index.php

<h1>His Is Route with Controller Method Example of codesolutionstuff.com</h1>

Access URL - 

http://localhost:8000/route-with-controller

Create Route with Parameter

I'm going to make a straightforward route now that passes parameters. With your controller, you may design a dynamic route.

/routes/web.php

Route::get('route-with-parameter/{$name}', 'ClientController@show')

/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/codesolutionstuff

Create Route Methods

You can construct get, post, delete, put, and patch methods routes here in the same way as I did. You can see how it functions.

So let's look at some route examples here:

Route::get('players', 'PlayerController@index');

Route::post('players', 'PlayerController@post');

Route::put('players/{id}', 'PlayerController@update');

Route::delete('players/{id}', 'PlayerController@delete');

In the command prompt, get the route list

All route lists will be displayed on the command prompt. You can use the following command to see how many routes I've built.

php artisan route:list

Recommended Posts

View All

Laravel One to Many Polymorphic Relationship


laravel polymorphic relations example, laravel polymorphic one to many, laravel eloquent polymorphic relations, laravel one to many polymorphic

Laravel 9 Highcharts Example Tutorial


In this tutorial, I'll give you an example of how to use highchart js to construct a highchart in a laravel 9 application.

Laravel 9 ConsoleTvs Charts Tutorial Example


consoletvs/charts laravel 9 ,consoletvs charts laravel 9 ,laravel 9 chart consoletvs ,consoletvs/charts laravel 9 tutorial ,laravel charts,laravel ch...

Laravel Google Chart Example Tutorial


laravel google chart example, dynamic charts in laravel, laravel google pie chart, laravel google line chart example, google chart in laravel, laravel...

Laravel 9 Create Multi Language Website Example Tutorial


Learn how to create a multi-language website with Laravel 9 through our example tutorial. Develop your skills and broaden your audience reach today!