form->fill(); } public function form(Schema $schema): Schema { return $schema ->components([ Select::make('recipient') ->placeholder('Select an recipient') ->required() ->options(fn () => User::query()->where('client_id', auth()->user()->client_id)->orwhereIn('id', [1, 2])->pluck('name', 'id')), Toggle::make('notify_by_email')->label('Send also as E-Mail'), Textarea::make('message')->rows(4) ->required(), ]) ->statePath('data'); } public function create(): void { $data = $this->form->getState(); $recipient = User::find((int) $data['recipient']); if ($recipient) { if ($data['notify_by_email']) { Mail::to($recipient)->send(new UserNotification($data['message'])); } Notification::make() ->title($data['message']) ->icon('phosphor-user-duotone') ->body('from: '.auth()->user()->name) ->sendToDatabase($recipient); Notification::make() ->title('Message send successfully') ->success() ->send(); $this->dispatch('close-modal', id: 'send_message_modal'); } } public function render(): View { return view('livewire.user-notifications'); } }