diff --git a/src/Routing/ResourceRegistrar.php b/src/Routing/ResourceRegistrar.php new file mode 100644 index 0000000..e39f8f0 --- /dev/null +++ b/src/Routing/ResourceRegistrar.php @@ -0,0 +1,35 @@ + + */ +class ResourceRegistrar extends IlluminateResourceRegistrar +{ + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Get the resource name for a grouped resource. + * + * @param string $prefix + * @param string $resource + * @param string $method + * @return string + */ + protected function getGroupResourceName($prefix, $resource, $method) + { + $group = trim(str_replace('/', '.', $this->router->getLastGroupPrefix()), '.'); + + if ( ! empty($group) && $group !== localization()->getCurrentLocale()) { + return trim("{$prefix}{$group}.{$resource}.{$method}", '.'); + } + + return trim("{$prefix}{$resource}.{$method}", '.'); + } +} diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 5a739d8..69c150b 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -27,6 +27,25 @@ protected function getActiveMiddlewares() return array_keys(array_filter($middleware)); } + /* ------------------------------------------------------------------------------------------------ + | Basic Route Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Route a resource to a controller. + * + * @param string $name + * @param string $controller + * @param array $options + * @return void + */ + public function resource($name, $controller, array $options = []) + { + $registrar = new ResourceRegistrar($this); + + $registrar->register($name, $controller, $options); + } + /* ------------------------------------------------------------------------------------------------ | Route Functions | ------------------------------------------------------------------------------------------------ diff --git a/tests/Stubs/Http/Controllers/BarController.php b/tests/Stubs/Http/Controllers/BarController.php new file mode 100644 index 0000000..999d4bc --- /dev/null +++ b/tests/Stubs/Http/Controllers/BarController.php @@ -0,0 +1,14 @@ + + */ +class BarController extends Controller +{ + // +} diff --git a/tests/Stubs/Http/Controllers/DummyController.php b/tests/Stubs/Http/Controllers/DummyController.php new file mode 100644 index 0000000..76d4af1 --- /dev/null +++ b/tests/Stubs/Http/Controllers/DummyController.php @@ -0,0 +1,14 @@ + + */ +class DummyController extends Controller +{ + // +} diff --git a/tests/Stubs/Http/RouteRegistrar.php b/tests/Stubs/Http/RouteRegistrar.php index 16217d1..a28c483 100644 --- a/tests/Stubs/Http/RouteRegistrar.php +++ b/tests/Stubs/Http/RouteRegistrar.php @@ -127,6 +127,16 @@ function () { return 'Any method'; } ]); + + /* ------------------------------------------------------------------------------------------------ + | Resource Controller + | ------------------------------------------------------------------------------------------------ + */ + $this->router->resource('dummy', Controllers\DummyController::class); + + $this->router->group(['prefix' => 'foo'], function () { + $this->router->resource('Bar', Controllers\BarController::class); + }); }); } }