spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

Unable to Access Campaign in Custom Mailable #237

Closed nkeena closed 3 years ago

nkeena commented 3 years ago

After updating the mailcoach package from version 2.21.0 to 2.22.0 and even the lastest 2.23.5, I am not able to access the campaign model in my custom mailable. Did something change? Now, $this->campaign returns null.

<?php

namespace App\Mail;

use App\EmailAttachment;
use Spatie\Mailcoach\Mails\CampaignMail;

class ClassMessage extends CampaignMail
{
    public $emailContent;

    public function build()
    {
        $this->emailContent = $this->campaign->html;

        $this
            ->from(
                $this->campaign->from_email ?? $this->campaign->emailList->default_from_email,
                $this->campaign->from_name ?? $this->campaign->emailList->default_from_name ?? null
            )
            ->subject($this->subject)
            ->view('emails.classes.message')
            ->addUnsubscribeHeaders()
            ->storeTransportMessageId();

        foreach (EmailAttachment::query()->where('campaign_id', $this->campaign->id)->get() as $attachment) {
            $this->attachFromStorage($attachment->source);
        }

        return $this;
    }
}
rubenvanassche commented 3 years ago

Hi @nkeena, if you upgrade to laravel-mailcoach 2.23.8 then this problem should be fixed. Thanks for using Mailcoach!