Version 2.0
This commit is contained in:
@@ -3,9 +3,38 @@
|
||||
namespace App\Filament\Resources\Contracts\Pages;
|
||||
|
||||
use App\Filament\Resources\Contracts\ContractResource;
|
||||
use App\Models\Contract;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateContract extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ContractResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
if (($data['status'] ?? '') === 'active') {
|
||||
$existing = Contract::where('product_id', $data['product_id'])
|
||||
->where('category', $data['category'])
|
||||
->where('status', 'active')
|
||||
->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