diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index 123b5c1fa..18e86bba4 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -186,8 +186,11 @@ public function __call($method, $parameters) * * @param Router $router * @param array $attributes + * @param bool $wrap Choose the routes defined in the @routes method, should be wrapped in a group with attributes by default. + * If true then all routes will be grouped in a configuration attributes passed by restify, otherwise + * you should take care of that, by adding $router->group($attributes) in the @routes method */ - public static function routes(Router $router, $attributes) + public static function routes(Router $router, $attributes, $wrap = false) { $router->group($attributes, function ($router) { // override for custom routes diff --git a/src/RestifyCustomRoutesProvider.php b/src/RestifyCustomRoutesProvider.php index 269143269..e654e2d38 100644 --- a/src/RestifyCustomRoutesProvider.php +++ b/src/RestifyCustomRoutesProvider.php @@ -41,13 +41,18 @@ protected function registerRoutes() $parameters = $method->getParameters(); - if (count($parameters) === 2 && $parameters[1] instanceof \ReflectionParameter) { -// $config = array_merge($config, $parameters[1]->getDefaultValue()); + $wrap = []; + + if (count($parameters) >= 2 && $parameters[1] instanceof \ReflectionParameter) { + $default = $parameters[1]->isDefaultValueAvailable() ? $parameters[1]->getDefaultValue() : []; + $config = array_merge($config, $default); + } + + if (count($parameters) === 3) { + $wrap = ($parameters[2]->isDefaultValueAvailable() && $parameters[2]->getDefaultValue()) ? $config : []; } - Route::group([], function ($router) use ($repository, $config) { - if ($repository === 'Binaryk\LaravelRestify\Tests\RepositoryWithRoutes') { - } + Route::group($wrap, function ($router) use ($repository, $config) { $repository::routes($router, $config); }); });