-
-
Notifications
You must be signed in to change notification settings - Fork 270
fix: compatible way to call the method on mailable #219
Conversation
The I tested the fix locally, not sure if we can do a require on composer with the branch number |
I got this error while testing it locally: Mailable: <?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ContactAdmin extends Mailable
{
use Queueable, SerializesModels;
public $name;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($name)
{
$this->name = $name;
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'Contact Admin',
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
markdown: 'default-mail',
with: [
'name' => $this->name,
],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
} |
Render works in some contexts then. I didn't get that error but does make sense as the returned value gets used later in to get the view data etc. I'll have to have another look in a few hours though at the moment 👍 |
we can use the render method to return the mailable preview |
Personal and reference Note: Lines 553 - 557 needs to change in the MailEclipse class as the mailables won't display after the fix works for Laravel 9 $collection = collect($fqcns)->map(function ($mailable) {
return $mailable;
+ });
- })->reject(function ($object) {
- return ! method_exists($object['namespace'], 'build');
- }); |
Currently working when there aren't things in the Mailables constructor. As when it is instanciated using the content method / render method it actually returns a model that doesn't have |
Thanks for the changes @ReeceM, I'll give it a try tonight and get back to you |
Thank you 👍 I suspect it will need some more work to get it working nicely. |
Indeed, it looks good to me, is it safe to push these changes as a quick fix for laravel 9? |
The changes are alright for Laravel 9 it shouldn't be breaking it further than it is at the moment because of the change in the Mailable methods. What might happen is the edge cases will be found for some who have a different setup. I did try and run it using an old mailable made with the build method and one made using the new style in a Laravel 9 app and both worked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good, it can be merged @ReeceM (y)
I'm going to open a new PR to make MailEclipse work with SymfonyMail after SwiftMailer was removed |
Okay cool 💯 I'll merge this and tag it |
Description
Adds a method exists check to the function of the buildMailable data method to check which method exists on the Mailable.
Related Issue
#218
Motivation and Context
This is to make the preview functionality work with Laravel 9
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: