Auto detect all routes in PHP Laravel application?

I created a custom user permission system in my bosses app that has a temporary webcam lock for employees, as well as pages to run reports from the database and many other company-related apps and pages.

The app is built with PHP and Laravel.

In my Laravel routes file, I have several sections that require admin authentication and others for user and login only.

Now that we are extending the application and I have created a permission system that will allow us to set page access on a page and based on user. I need to do away with my route validation requirements and instead set permissions on the page using my new per-user permission settings.

So my question is, how can I automatically detect every page.route file in the application so that on my permission page I can show an entry for every page in the application?

In the following figure, each page has been manually added to a database table. Now I need to automatically detect all routes in the application instead.

enter image description here

+3


source to share


1 answer


I posted this question too early. Now I can see that there is a methodgetRoutes()

Code from answer fooobar.com/questions/160467 / ...



Route::get('routes', function() {
$routeCollection = Route::getRoutes();

echo "<table style='width:100%'>";
    echo "<tr>";
        echo "<td width='10%'><h4>HTTP Method</h4></td>";
        echo "<td width='10%'><h4>Route</h4></td>";
        echo "<td width='80%'><h4>Corresponding Action</h4></td>";
    echo "</tr>";
    foreach ($routeCollection as $value) {
        echo "<tr>";
            echo "<td>" . $value->getMethods()[0] . "</td>";
            echo "<td>" . $value->getPath() . "</td>";
            echo "<td>" . $value->getActionName() . "</td>";
        echo "</tr>";
    }
echo "</table>";
});

      

+2


source







All Articles