Last active
March 15, 2016 21:09
-
-
Save lagbox/0a1e3f8786f3fd425e44 to your computer and use it in GitHub Desktop.
Resource Registrar, add a parameter to show routes
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\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 | |
); | |
} | |
} |
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\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