Skip to content

Commit 2809a64

Browse files
committed
replicate fields
1 parent a5d64e7 commit 2809a64

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Filament/RelationManagers/FieldsRelationManager.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ public function table(Table $table): Table
269269
->recordActions([
270270
EditAction::make()
271271
->slideOver()
272+
->hiddenLabel()
272273
->mutateRecordDataUsing(function (array $data) {
273274

274275
return [
@@ -278,9 +279,27 @@ public function table(Table $table): Table
278279
];
279280
})
280281
->after(function (Component $livewire) {
282+
$livewire->dispatch('refreshFields');
283+
}),
284+
Action::make('replicate')
285+
->tooltip(__('Duplicate'))
286+
->hiddenLabel()
287+
->icon('heroicon-o-document-duplicate')
288+
->action(function (Field $record, Component $livewire) {
289+
$replica = $record->replicate();
290+
$replica->ulid = (string) Str::ulid();
291+
$replica->name = $record->name . ' (' . __('Copy') . ')';
292+
$replica->slug = Str::slug($replica->name);
293+
$replica->position = Field::where('model_key', $this->ownerRecord->getKey())
294+
->where('model_type', get_class($this->ownerRecord))
295+
->max('position') + 1;
296+
$replica->save();
297+
281298
$livewire->dispatch('refreshFields');
282299
}),
283300
DeleteAction::make()
301+
->hiddenLabel()
302+
->tooltip(__('Delete'))
284303
->after(function (Component $livewire, array $data, Model $record, array $arguments) {
285304
if (
286305
isset($record->valueColumn) && $this->ownerRecord->getConnection()

0 commit comments

Comments
 (0)