Created
November 9, 2018 12:25
-
-
Save carbontwelve/ebcdd164ed7206206ce4da6e8401265e to your computer and use it in GitHub Desktop.
Command that overloads the laravel route:list and adds tenant aware capabilities.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Foundation\Console\RouteListCommand as BaseRouteListCommand; | |
use Illuminate\Routing\RouteCollection; | |
use Illuminate\Routing\UrlGenerator; | |
use Symfony\Component\Console\Input\InputOption; | |
class RouteListCommand extends BaseRouteListCommand | |
{ | |
public function handle() | |
{ | |
if ($path = config('tenancy.routes.path')) { | |
if ($this->option('tenant')) { | |
$this->router->setRoutes(new RouteCollection()); | |
} | |
/** @var UrlGenerator $url */ | |
$url = app('url'); | |
$this->router->middleware([])->group($path); | |
$this->router->getRoutes()->refreshNameLookups(); | |
$url->setRoutes($this->router->getRoutes()); | |
$this->routes = $this->router->getRoutes(); | |
} | |
parent::handle(); | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
return array_merge([ | |
['tenant', null, InputOption::VALUE_NONE, 'Display only tenant routes'], | |
], parent::getOptions()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment