craigpaul / laravel-postmark

A Postmark adapter for Laravel
MIT License
204 stars 23 forks source link

Typed property error on 'id' when using alias instead of identifier #135

Closed leeuweriq closed 2 years ago

leeuweriq commented 2 years ago

Detailed description

I encoutered this bug when creating a new TemplatedMailMessage and using the 'alias' directive instead of using an identifier. My code looks like this:

$message = (new TemplatedMailMessage())
            ->from(
                config('mail.from.address'),
                config('mail.from.name'))
            ->alias($this->templateId)
            ->include($this->templateModel($notifiable));

In the 2.x versions of your package this worked. But in the 3.x version it throws this error:

Error: Typed property CraigPaul\Mail\TemplatedMailMessage::$id must not be accessed before initialization in /.../vendor/coconutcraig/laravel-postmark/src/TemplatedMailMessage.php:27

However, when adding the "identifier" with value '0' it does work:

$message = (new TemplatedMailMessage())
            ->from(
                config('mail.from.address'),
                config('mail.from.name'))
            ->identifier(0)
            ->alias($this->templateId)
            ->include($this->templateModel($notifiable));

Possible implementation

Change the id property on the TemplatedMailMessage class to this:

protected ?int $id = null;

Your environment

craigpaul commented 2 years ago

Hey @leeuweriq,

Thanks for catching this. I'll have a fix out in just a little bit