Skip to content

Commit

Permalink
fix duplicating child module for nested modules
Browse files Browse the repository at this point in the history
  • Loading branch information
zeezo887 authored and ifox committed May 23, 2024
1 parent a068e1b commit 4b91add
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Http/Controllers/Admin/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,29 @@ public function duplicate($id, $submoduleId = null)
$this->fireEvent();
activity()->performedOn($item)->log('duplicated');

// For nested module
if (Str::contains($this->moduleName, '.')) {
$moduleName = Str::afterLast($this->moduleName, '.');
$singularParentModuleName = Str::singular(Str::beforeLast($this->moduleName, '.'));

$parameters = [
Str::singular($moduleName) => $newItem->id,
$singularParentModuleName => request()->query($singularParentModuleName),
];
} else {
$parameters = [
Str::singular($this->moduleName) => $newItem->id,
];
}

return Response::json([
'message' => twillTrans('twill::lang.listing.duplicate.success', ['modelTitle' => $this->modelTitle]),
'variant' => FlashLevel::SUCCESS,
'redirect' => moduleRoute(
$this->moduleName,
$this->routePrefix,
'edit',
array_filter([Str::singular($this->moduleName) => $newItem->id])
array_filter($parameters)
),
]);
}
Expand Down

0 comments on commit 4b91add

Please sign in to comment.