asahasrabuddhe / laravel-mjml

Easily use MJML in your Laravel Blade templates!
MIT License
122 stars 51 forks source link

fix public properties not available in the view #150

Closed eklundkristoffer closed 1 year ago

eklundkristoffer commented 1 year ago

This PR will fix an issue with public properties not being available in the view.

For example, this will not work:

class MyMail extends Mailable
{
    use Queueable, SerializesModels;

    public $myPublicProperty = 'Hello World';

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    public function content()
    {
        return new Content(
            view: $this->mjml('emails.thanks-for-your-application')->buildMjmlView()['html'],
        );
    }
}

What will work with current code is by pass it in the with within Content definition.

class MyMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    public function content()
    {
        return new Content(
            view: $this->mjml('emails.thanks-for-your-application')->buildMjmlView()['html'],
            with: [
                'myPublicProperty' => 'Hello World',
            ]
        );
    }
}