Skip to content

Commit

Permalink
fix: change routes generation to kebab hyphen dashed type
Browse files Browse the repository at this point in the history
  • Loading branch information
mitulgolakiya committed Jun 23, 2022
1 parent 0b1160f commit 8405887
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 14 deletions.
8 changes: 2 additions & 6 deletions src/Common/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ public function loadDynamicVariables(CommandData &$commandData)
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_SNAKE$', $this->mSnakePlural);
$commandData->addDynamicVariable('$MODEL_NAME_DASHED$', $this->mDashed);
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_DASHED$', $this->mDashedPlural);
$commandData->addDynamicVariable('$MODEL_NAME_SLASH$', $this->mSlash);
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_SLASH$', $this->mSlashPlural);
$commandData->addDynamicVariable('$MODEL_NAME_HUMAN$', $this->mHuman);
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_HUMAN$', $this->mHumanPlural);
$commandData->addDynamicVariable('$FILES$', '');
Expand Down Expand Up @@ -368,10 +366,8 @@ public function prepareModelNames()
$this->mCamelPlural = Str::camel($this->mPlural);
$this->mSnake = Str::snake($this->mName);
$this->mSnakePlural = Str::snake($this->mPlural);
$this->mDashed = str_replace('_', '-', Str::snake($this->mSnake));
$this->mDashedPlural = str_replace('_', '-', Str::snake($this->mSnakePlural));
$this->mSlash = str_replace('_', '/', Str::snake($this->mSnake));
$this->mSlashPlural = str_replace('_', '/', Str::snake($this->mSnakePlural));
$this->mDashed = Str::kebab($this->mName);
$this->mDashedPlural = Str::kebab($this->mPlural);
$this->mHuman = Str::title(str_replace('_', ' ', Str::snake($this->mSnake)));
$this->mHumanPlural = Str::title(str_replace('_', ' ', Str::snake($this->mSnakePlural)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Generators/API/APIRoutesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function generate()
{
$this->routeContents .= "\n\n".$this->routesTemplate;
$existingRouteContents = file_get_contents($this->path);
if (Str::contains($existingRouteContents, "Route::resource('".$this->commandData->config->mSnakePlural."',")) {
$this->commandData->commandObj->info('Menu '.$this->commandData->config->mPlural.'is already exists, Skipping Adjustment.');
if (Str::contains($existingRouteContents, "Route::resource('".$this->commandData->config->mDashedPlural."',")) {
$this->commandData->commandObj->info('Menu '.$this->commandData->config->mDashedPlural.'is already exists, Skipping Adjustment.');

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Generators/Scaffold/RoutesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function generate()
{
$this->routeContents .= "\n\n".$this->routesTemplate;
$existingRouteContents = file_get_contents($this->path);
if (Str::contains($existingRouteContents, "Route::resource('".$this->commandData->config->mSnakePlural."',")) {
$this->commandData->commandObj->info('Route '.$this->commandData->config->mPlural.' is already exists, Skipping Adjustment.');
if (Str::contains($existingRouteContents, "Route::resource('".$this->commandData->config->mDashedPlural."',")) {
$this->commandData->commandObj->info('Route '.$this->commandData->config->mDashedPlural.' is already exists, Skipping Adjustment.');

return;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/api/routes/prefix_routes.stub
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Route::group(['prefix' => '$RAW_ROUTE_PREFIX$'], function () {
Route::resource('$MODEL_NAME_PLURAL_SNAKE$', $NAMESPACE_API_CONTROLLER$\$MODEL_NAME$APIController::class);
Route::resource('$MODEL_NAME_PLURAL_DASHED$', $NAMESPACE_API_CONTROLLER$\$MODEL_NAME$APIController::class);
});
2 changes: 1 addition & 1 deletion templates/api/routes/routes.stub
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Route::resource('$MODEL_NAME_PLURAL_SNAKE$', $NAMESPACE_API_CONTROLLER$\$MODEL_NAME$APIController::class);
Route::resource('$MODEL_NAME_PLURAL_DASHED$', $NAMESPACE_API_CONTROLLER$\$MODEL_NAME$APIController::class);
2 changes: 1 addition & 1 deletion templates/scaffold/routes/prefix_routes.stub
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Route::group(['prefix' => '$RAW_ROUTE_PREFIX$'], function () {
Route::resource('$MODEL_NAME_PLURAL_CAMEL$', $NAMESPACE_CONTROLLER$\$MODEL_NAME$Controller::class, ["as" => '$RAW_ROUTE_PREFIX$']);
Route::resource('$MODEL_NAME_PLURAL_DASHED$', $NAMESPACE_CONTROLLER$\$MODEL_NAME$Controller::class, ["as" => '$RAW_ROUTE_PREFIX$']);
});
2 changes: 1 addition & 1 deletion templates/scaffold/routes/routes.stub
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Route::resource('$MODEL_NAME_PLURAL_CAMEL$', $NAMESPACE_CONTROLLER$\$MODEL_NAME$Controller::class);
Route::resource('$MODEL_NAME_PLURAL_DASHED$', $NAMESPACE_CONTROLLER$\$MODEL_NAME$Controller::class);

0 comments on commit 8405887

Please sign in to comment.