<?php namespace App\Mail; use App\Models\Blog; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Queue\SerializesModels; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Contracts\Queue\ShouldQueue; class BlogMail extends Mailable implements ShouldQueue { use Queueable, SerializesModels; public $subject; public $blogs; /** * Create a new message instance. */ public function __construct(private $ids) { $this->blogs = Blog::whereIn('id', $this->ids)->get(); $this->subject .= "BFTI Blog || "; // Looping through blogs to construct the subject foreach ($this->blogs as $index => $blog) { // Append the title of the blog to the subject $this->subject .= $blog->title; // Check if this is not the last blog in the collection if ($index < $this->blogs->count() - 1) { $this->subject .= ' || '; } $blog->mail_status = true; $blog->save(); } } /** * Get the message envelope. */ public function envelope(): Envelope { return new Envelope( subject: $this->subject, ); } /** * Get the message content definition. */ public function content(): Content { return new Content( markdown: 'mail.blog-mail', with: [ 'blogs' => $this->blogs, 'title' => "BFTI Blog" ] ); } /** * Get the attachments for the message. * * @return array<int, \Illuminate\Mail\Mailables\Attachment> */ public function attachments(): array { return []; } }