F
Filamentβ€’2mo ago
larsbo

Replicate - but display form instead of saving directly.

I want to duplicate a model instance and some required fields should be ignored. In this case the standard replicate action fails because the confirm modal only shows a confirm button and by pressing it the duplicated cannot be saved in the database because of the ignored non-nullable columns. I found this v3 thread but the solution does not work: https://discord.com/channels/883083792112300104/1245204314645987399 After analyzing the core code I found that the solution as simple as adding a $this->schema() . So here is my working custom action class that displays my form inside the replicate modal and allows to fill out the not replicated, required fields:
class ReplicateToolAction extends ReplicateAction
{
protected function setUp(): void
{
parent::setUp();

$this->schema(fn (Schema $schema) => ToolForm::configure($schema)); // the simple solution

$this->excludeAttributes([
'inventory_number',
'serial_number',
'last_maintenance_at',
]);
}
}
class ReplicateToolAction extends ReplicateAction
{
protected function setUp(): void
{
parent::setUp();

$this->schema(fn (Schema $schema) => ToolForm::configure($schema)); // the simple solution

$this->excludeAttributes([
'inventory_number',
'serial_number',
'last_maintenance_at',
]);
}
}
Maybe this helps other. πŸ˜€
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?