Skip to content

Instantly share code, notes, and snippets.

@jarektkaczyk
Created September 8, 2016 02:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarektkaczyk/09c2540564ccbe31b2540a03687125b0 to your computer and use it in GitHub Desktop.
Save jarektkaczyk/09c2540564ccbe31b2540a03687125b0 to your computer and use it in GitHub Desktop.
Handy helper for working with route list in tinker [Laravel]
<?php
// Easily get route list in tinker
>>> app('RouteList')->setOption('method', 'PUT')->getRoutes()
>>> app('RouteList')->getRoutes()->where('name', 'website.login')
class RouteList extends \Illuminate\Foundation\Console\RouteListCommand
{
/** @var array */
public $options;
protected $laravel;
public function __construct(Illuminate\Routing\Router $router)
{
parent::__construct($router);
$this->setLaravel(app());
}
public function getRoutes()
{
return collect(parent::getRoutes())->values();
}
public function setOption($key, $value)
{
$this->options[$key] = $value;
return $this;
}
public function option($key=null)
{
return data_get($this->options, $key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment