【问题标题】:How to use with routes in Laravel 5.6?如何在 Laravel 5.6 中使用路由?
【发布时间】:2018-09-07 02:47:05
【问题描述】:

我在 Laravel 5.6 中创建了 2 条路线(web.phpadmin.php)。

RouteServiceProvider.php:

public function map()
{
    $this->mapApiRoutes();

    $this->mapWebRoutes();

    $this->mapAdminRoutes();
}

protected function mapWebRoutes()
{
    Route::middleware('web')
         ->namespace($this->namespace)
         ->group(base_path('routes/web.php'));
}

protected function mapAdminRoutes()
{
    Route::middleware(['web', 'adminInformation'])
        ->prefix('manage')
        ->namespace($this->namespace)
        ->group(base_path('routes/admin.php'));
}

现在我只需要在admin.php 中获取控制器名称。

例如:

$r = \Route::getRoutes();
    foreach ($r as $value) {

        echo($value->getName() . "<br />");
    }

方法Route::getRoutes()显示所有路由(web.php & admin.php)。

如何仅从admin.php 获取名称控制器?

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    可以按前缀过滤:

    $routerCollection = \Route::getRoutes();
    foreach ($routerCollection as $route) {
        if ($route->getPrefix() == 'manage') {
            echo($value->getName() . "<br />");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-10
      • 2018-12-06
      • 1970-01-01
      • 2018-08-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 2018-12-18
      相关资源
      最近更新 更多