*/ protected array $_rolesPicked = []; protected function handleRecordCreation(array $data): Model { try { return parent::handleRecordCreation($data); } catch (UniqueConstraintViolationException $e) { $msg = str_contains($e->getMessage(), 'email') ? __('Acest email este deja folosit de un alt utilizator.') : __('Acest număr de telefon este deja folosit de un alt utilizator.'); Notification::make()->danger()->title($msg)->send(); throw new Halt(); } } protected function mutateFormDataBeforeCreate(array $data): array { $this->_rolesPicked = $data['roles_picked'] ?? []; unset($data['roles_picked']); return $data; } protected function afterCreate(): void { $picked = $this->_rolesPicked; if (! in_array($this->record->role, $picked, true)) { $picked[] = $this->record->role; } $this->record->syncRoles(array_unique($picked)); } }