34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
|
|
|
|
use App\Filament\User\Resources\SpiceSupplierResource;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Filament\Notifications\Notification;
|
|
use App\Models\Spice;
|
|
|
|
class EditSpiceSupplier extends EditRecord
|
|
{
|
|
protected static string $resource = SpiceSupplierResource::class;
|
|
|
|
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
\Filament\Actions\DeleteAction::make()->before(function ($record) {
|
|
if (!$record->spice || $record->spice->quantity < $record->amount) {
|
|
Notification::make()
|
|
->warning()
|
|
->title('Fehler!')
|
|
->body('Nicht mehr genügend ' . htmlentities($record->spice->name) . ' im Lager (bräuchte mindestens Liefermenge um Lieferung rückgängig zu machen)')
|
|
->send();
|
|
$this->halt();
|
|
return false;
|
|
}
|
|
Spice::findOrFail($record->spice->id)->decrement('quantity', $record->amount);
|
|
}),
|
|
];
|
|
}
|
|
}
|