Categories: Development

Create a table of your Laravel routes

A method to view your Laravel routes with PHP code that is an alternative to the command php artisan route:list --except-vendor.

In this post the routes will be displayed in a HTML table.

getRoutes will return all routes in the collection as an array

$routes = Route::getRoutes();

Then you can loop over each route and get specific data by accessing its keys

foreach ($routes as $value) {
    $value->methods()[0];
    $value->uri();
    $value->getName();
    $value->getActionName();
}

Integrate this into a table for easy examination

echo "<div class='table-responsive'>";
echo "<table class='table table-bordered'>";
echo "<tr>";
echo "<td><h4>HTTP Method</h4></td>";
echo "<td><h4>Route</h4></td>";
echo "<td><h4>Name</h4></td>";
echo "<td><h4>Action</h4></td>";
echo "</tr>";
foreach ($routes as $value) {
    echo "<tr>";
    echo "<td>" . $value->methods()[0] . "</td>";
    echo "<td>" . $value->uri() . "</td>";
    echo "<td>" . $value->getName() . "</td>";
    echo "<td>" . $value->getActionName() . "</td>";
    echo "</tr>";
}
echo "</table>";
echo "</div>";

 

 

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago