mySun
mySun

Reputation: 1696

How to use with routes in Laravel 5.6?

I create 2 route (web.php and admin.php) in Laravel 5.6.

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

Now i need get just controller names in admin.php.

For example:

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

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

Method Route::getRoutes() show all routes (web.php & admin.php).

How to get name controller just from admin.php?

Upvotes: 1

Views: 644

Answers (1)

Ben
Ben

Reputation: 5129

Can filter by prefix:

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

Upvotes: 2

Related Questions