Skip to content

Commit

Permalink
fix(routes): Modules' plural routes fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalealvarezs committed Sep 11, 2022
1 parent 48ce885 commit 8f99ca1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Utilities/PbUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function buildCrudRoutes($type): void
}
switch ($type) {
case 'web':
Route::resource($name . 's', $controllerClass)->middleware([
Route::resource(Str::plural($name), $controllerClass)->middleware([
...getDefaultGroupsMiddlewares('web'),
...getDefaultGroupsMiddlewares('auth'),
...getDefaultGroupsMiddlewares('debug'),
Expand All @@ -75,7 +75,7 @@ public function buildCrudRoutes($type): void
...getDefaultGroupsMiddlewares('web'),
...getDefaultGroupsMiddlewares('auth'),
...getDefaultGroupsMiddlewares('debug'),
'role_or_permission:update '. $name . 's'
'role_or_permission:update '. Str::plural($name)
]
],
fn() => $this->buildAdditionalCrudRoutes($name, $modelClass, $controllerClass, false, true)
Expand All @@ -84,7 +84,7 @@ public function buildCrudRoutes($type): void
default:
Route::prefix('api')->group(
function() use ($name, $modelClass, $controllerClass) {
Route::resource($name . 's', $controllerClass)->middleware([
Route::resource(Str::plural($name), $controllerClass)->middleware([
...getDefaultGroupsMiddlewares('api'),
...getDefaultGroupsMiddlewares('auth'),
])->names(getApiRoutesNames($name));
Expand All @@ -94,7 +94,7 @@ function() use ($name, $modelClass, $controllerClass) {
'middleware' => [
...getDefaultGroupsMiddlewares('api'),
...getDefaultGroupsMiddlewares('auth'),
'role_or_permission:update '. $name . 's'
'role_or_permission:update '. Str::plural($name)
]
],
fn() => $this->buildAdditionalCrudRoutes($name, $modelClass, $controllerClass, true)
Expand All @@ -119,22 +119,22 @@ function() use ($name, $modelClass, $controllerClass) {
*/
protected function buildAdditionalCrudRoutes($name, $modelClass, $controllerClass, bool $api = false, bool $sortable = false)
{
Route::prefix($name . 's')->group(
Route::prefix(Str::plural($name))->group(
function() use ($name, $modelClass, $controllerClass, $api, $sortable) {
Route::get('page/{page?}/{perpage?}/{orderby?}/{field?}/{order?}', [$controllerClass, 'index'])->where([
'page' => '[0-9]+',
'perpage' => '[0-9]+',
'orderby' => 'order',
'field' => '[a-zA-Z0-9_]+',
'order' => 'asc|desc',
])->name(($api ? 'api.' : '').$name . 's.index.paginated');
])->name(($api ? 'api.' : '').Str::plural($name) . '.index.paginated');
Route::prefix('{navigation}')->group(function () use ($name, $modelClass, $controllerClass, $api, $sortable) {
if (isset($modelClass::$sortable) && $sortable) {
Route::match(array('PUT', 'PATCH'), 'sort', [$controllerClass, 'sort'])->name(($api ? 'api.': '') . $name . 's.sort');
Route::match(array('PUT', 'PATCH'), 'sort', [$controllerClass, 'sort'])->name(($api ? 'api.': '') . Str::plural($name) . '.sort');
}
if (isset($modelClass::$enableable)) {
Route::match(array('PUT', 'PATCH'), 'enable', [$controllerClass, 'enable'])->name(($api ? 'api.': '') . $name . 's.enable');
Route::match(array('PUT', 'PATCH'), 'disable', [$controllerClass, 'disable'])->name(($api ? 'api.': '') . $name . 's.disable');
Route::match(array('PUT', 'PATCH'), 'enable', [$controllerClass, 'enable'])->name(($api ? 'api.': '') . Str::plural($name) . '.enable');
Route::match(array('PUT', 'PATCH'), 'disable', [$controllerClass, 'disable'])->name(($api ? 'api.': '') . Str::plural($name) . '.disable');
}
});
}
Expand Down

0 comments on commit 8f99ca1

Please sign in to comment.