Files
SpiceManagementSystem/app/Filament/User/Resources/SpiceSupplierResource/Pages/EditSpiceSupplier.php
T
Malek TellissiandClaude Sonnet 4.6 70eb5170d1
Deploy / deploy (push) Successful in 15s
Allow deleting spice deliveries even with insufficient stock; warn instead of block
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>
2026-09-12 21:46:47 +02:00

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),
]);
}
}),
];
}
}