Skip to content

Instantly share code, notes, and snippets.

@lagbox
Last active March 15, 2016 21:09
Show Gist options
  • Save lagbox/0a1e3f8786f3fd425e44 to your computer and use it in GitHub Desktop.
Save lagbox/0a1e3f8786f3fd425e44 to your computer and use it in GitHub Desktop.
Resource Registrar, add a parameter to show routes
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(
\Illuminate\Routing\ResourceRegistrar::class,
\App\Lib\ResourceRegistrar::class
);
}
}
<?php
namespace App\Lib;
use Illuminate\Routing\ResourceRegistrar as BaseRegistrar;
class ResourceRegistrar extends BaseRegistrar
{
// force it to define edit before show to avoid conflicting routes
protected $resourceDefaults = ['index', 'create', 'store', 'edit', 'show', 'update', 'destroy'];
public function addResourceShow($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name). '/{'. $base .'}';
if (isset($options['slug']) && $options['slug']) {
$uri .= '/{slug}';
}
$action = $this->getResourceAction($name, $controller, 'show', $options);
return $this->router->get($uri, $action);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment