Version 2.0
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
namespace App\Filament\Resources\Contracts\Pages;
|
||||
|
||||
use App\Filament\Resources\Contracts\ContractResource;
|
||||
use App\Models\Contract;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditContract extends EditRecord
|
||||
@@ -16,4 +18,32 @@ class EditContract extends EditRecord
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
if (($data['status'] ?? '') === 'active') {
|
||||
$existing = Contract::where('product_id', $data['product_id'])
|
||||
->where('category', $data['category'])
|
||||
->where('status', 'active')
|
||||
->where('id', '!=', $this->getRecord()->id)
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
Notification::make()
|
||||
->title(__('feedback.contract_duplicate_title', [
|
||||
'category' => \App\Enums\ContractCategory::from($data['category'])->label(),
|
||||
]))
|
||||
->body(__('feedback.contract_duplicate_body', [
|
||||
'product' => $existing->product?->name ?? '?',
|
||||
'customer' => $existing->customer?->name ?? '?',
|
||||
]))
|
||||
->warning()
|
||||
->send();
|
||||
|
||||
$this->halt();
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user