laravel

How to get list of all routes in Laravel

How-to-get-list-of-all-routes-in-Laravel.png

In this article we will see how to show all routes in larval with different methods. This article is explained step-by-step how to get list of all routes in Laravel. We are sharing two simple way to get list of all routes in Laravel.

Using getRoutes() Method:

Step 01: Routes Creating

First we need to create routes for showing list of routes.

Routes/web.php

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ListRoutes;
Route::get('get-all-routes', [ListRoutes::class, 'index']);

Step 02: Controller creating

After updating web.php file then create a controller with the name of ListRoutes. Run the given command to make controller.

Php artisan make:controller ListRoutes

Then open the created controller following the way

App/Http/Controllers/ListRoutes

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
class ListRoutes extends Controller
{
    public function index(Request $request)
    {
        $routes = Route::getRoutes();
        return view('route-list', compact('routes'));
    }
}

Step 03: Views File creating

In this step we need to make blade file with the name of routesList.blade.php to show list of routes. Here is the code update the created file.

Resouces/views/routesList.blade.php

Run the server

After completing the all steps run the server by using this command.

Php artisan serve

So open this url to check the list of routes.

http://localhost:8000/get-all-routes

Thank you for our article. I hope it will helpful for you.



About author

IMG_8897.png

Muhammad Zubair

My name is Muhammad Zubair. I'm a full-stack developer. I'm a owner of theskillstock.com. I love to write tutorials of PHP, Laravel, Html & css, Javascript, Java and much more with examples.


Comments

No Comments Yet.



Leave a Reply