
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.
No Comments Yet.