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'), TextInput::make('subject') ->required(), MarkdownEditor::make('message') ->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['subject'], $data['message'])); } Notification::make() ->title($data['subject']) ->icon('phosphor-envelope-duotone') ->body($data['message']) ->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'); } }