-
app/Jobs/SendEmailJob.php
Open in GitHubuse App\Mail\SendChatToEmail; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; class SendEmailJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $details; public function __construct($details) { $this->details = $details; } public function handle(): void { Log::info('Sending email to '.$this->details['email']); $email = new SendChatToEmail($this->details); Mail::to($this->details['email'])->send($email); } }
-
app/Http/Livewire/ChatBox.php
Open in GitHubuse Livewire\Component; class ChatBox extends Component { // ... public function sendChatToEmail() { if ($this->messages === []) { $this->alert('error', 'You have not started a conversation yet!', [ 'position' => 'top-end', 'timer' => 3000, 'toast' => true, ]); } else { $details = [ 'email' => auth()->user()->email, 'messages' => $this->messages, ]; dispatch(new \App\Jobs\SendEmailJob($details)); $this->alert('success', 'Your email was sent successfully!', [ 'position' => 'top-end', 'timer' => 3000, 'toast' => true, ]); } } // ... }