Files
landing-api/app/Filament/Support/DuplicateAction.php
Josep Piguillem 366568b793 Duplicate records as drafts, and preview them from the form
The copy keeps the content, stack and team, but is unpublished, out of any
review, and gets a title marked as a copy and a free slug. It replaces
Filament's replicate action, which left the copy without a slug and still
published. The same copy is available through the API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 10:14:51 +02:00

39 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Support;
use App\Support\Duplicator;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Model;
/**
* "Duplicate": a draft copy to start the next one from, opened straight away.
*/
final class DuplicateAction
{
public static function make(): Action
{
return Action::make('duplicate')
->label(__('panel.duplicate.label'))
->icon('heroicon-o-document-duplicate')
->color('gray')
->requiresConfirmation()
->modalHeading(__('panel.duplicate.heading'))
->modalDescription(__('panel.duplicate.hint'))
->authorize('create')
->action(function (Model $record, $livewire): void {
$copy = Duplicator::duplicate($record);
Notification::make()
->title(__('panel.duplicate.done'))
->success()
->send();
$livewire->redirect($livewire::getResource()::getUrl('edit', ['record' => $copy]));
});
}
}