asahasrabuddhe / laravel-mjml

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

[Question] Confused as to what to do at step 4. #148

Open mariusberget92 opened 1 year ago

mariusberget92 commented 1 year ago

Hi. I am a bit confused as to what to do when I come to step 4: In the build method, use: $this->mjml('view.name');

When I generated the mail class, I cannot see any build method anywhere. When I try to add the build method, VSCode suggests a buildViewData method instead. I added the whole generated mail class below. Sorry if I have misunderstood something.

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Asahasrabuddhe\LaravelMJML\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class EmailVerificationMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the message envelope.
     *
     * @return \Illuminate\Mail\Mailables\Envelope
     */
    public function envelope()
    {
        return new Envelope(
            subject: 'Email Verification Mail',
        );
    }

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    public function content()
    {
        return new Content(
            view: 'view.name',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array
     */
    public function attachments()
    {
        return [];
    }
}
rizaljamhari commented 1 year ago

In Laravel 9, there's no build method anymore. It was replaced by content method. For Laravel 9, use this:

public function content()
{
    return new Content(
        view: $this->mjml('view.name')->buildMjmlView()['html'],
    );
}
mariusberget92 commented 1 year ago

In Laravel 9, there's no build method anymore. It was replaced by content method. For Laravel 9, use this:

public function content()
{
    return new Content(
        view: $this->mjml('view.name')->buildMjmlView()['html'],
    );
}

Thank you! :)