Skip to content

Instantly share code, notes, and snippets.

@carbontwelve
Created November 9, 2018 12:25
Show Gist options
  • Save carbontwelve/ebcdd164ed7206206ce4da6e8401265e to your computer and use it in GitHub Desktop.
Save carbontwelve/ebcdd164ed7206206ce4da6e8401265e to your computer and use it in GitHub Desktop.
Command that overloads the laravel route:list and adds tenant aware capabilities.
<?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