Deploy / deploy (push) Successful in 15s
Shows a warning in the confirmation dialog when stock would go below zero. Deletion proceeds and sets stock to 0 rather than blocking the action. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
|
|
|
|
use App\Filament\User\Resources\SpiceSupplierResource;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditSpiceSupplier extends EditRecord
|
|
{
|
|
protected static string $resource = SpiceSupplierResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
\Filament\Actions\DeleteAction::make()
|
|
->requiresConfirmation()
|
|
->modalHeading('Lieferung löschen')
|
|
->modalDescription(fn ($record) => $record->spice && $record->spice->quantity < $record->amount
|
|
? 'Warnung: Nicht mehr genügend ' . $record->spice->name . ' im Lager. Der Bestand wird auf 0 gesetzt. Trotzdem löschen?'
|
|
: 'Soll diese Lieferung wirklich gelöscht werden?'
|
|
)
|
|
->before(function ($record) {
|
|
if ($record->spice) {
|
|
$record->spice->update([
|
|
'quantity' => max(0, $record->spice->quantity - $record->amount),
|
|
]);
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
}
|