craigpaul/laravel-postmark

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

leeuweriq opened this issue · 1 comments

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

  • Laravel Postmark Version: 3.0.1
  • Laravel Version: 9.1.0
  • PHP Version: 8.0

Hey @leeuweriq,

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