在拉拉维尔显示已注册的路线

2022-08-30 22:30:04

在这个截屏视频中:https://tutsplus.com/lesson/displaying-registered-routes/ Jeffrey Way演示了他创建的命令,并在描述中链接到github。然而,有一个更新说它现在已经融入Laravel 4核心,但是我已经搜索了它,但无济于事。

一般的想法是列出所有路由,并且操作绑定到它们。

任何帮助将不胜感激。


答案 1

控制台命令:

php artisan routes (laravel 4)
php artisan route:list (laravel 5)


+--------+----------------------------------------------------+-----------------------+----------------------------------------------+--------------------------------------------------------------------+---------------+
| Domain | URI                                                | Name                  | Action                                       | Before Filters                                                     | After Filters |
+--------+----------------------------------------------------+-----------------------+----------------------------------------------+--------------------------------------------------------------------+---------------+
|        | GET /admin/configuration                           |                       | ConfigurationController@index                | auth, keyMaster:configuration                                      |               |
|        | POST /admin/configuration                          |                       | ConfigurationController@update               | auth, keyMaster:configuration                                      |               |
|        | GET /admin/logs/errors                             |                       | LogsController@errors                        | auth, keyMaster:logs/errors                                        |               |
|        | GET /admin/logs/errors/{name}                      |                       | LogsController@errors                        | auth, keyMaster:logs/errors                                        |               |
|        | DELETE /admin/logs/errors                          |                       | LogsController@delete                        | auth, keyMaster:logs/errors                                        |               |
|        | GET /admin/logs/events                             |                       | LogsController@events                        | auth, keyMaster:logs/events                                        |               |
|        | GET /admin/logs/events/data                        |                       | LogsController@eventsData                    | auth, keyMaster:logs/events                                        |               |

等。。。


答案 2

我创建了一个路由,它将在html表中列出每个路由及其各自的详细信息。

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>";
});

推荐