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…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago