Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Alternative Mailable Syntax #44462

Merged
merged 23 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Illuminate/Foundation/Console/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ protected function writeMarkdownTemplate()
*/
protected function buildClass($name)
{
$class = parent::buildClass($name);
$class = str_replace(
'{{ subject }}',
Str::headline(str_replace($this->getNamespace($name).'\\', '', $name)),
parent::buildClass($name)
);

if ($this->option('markdown') !== false) {
$class = str_replace(['DummyView', '{{ view }}'], $this->getView(), $class);
Expand Down
34 changes: 30 additions & 4 deletions src/Illuminate/Foundation/Console/stubs/mail.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace {{ namespace }};
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 {{ class }} extends Mailable
Expand All @@ -22,12 +24,36 @@ class {{ class }} extends Mailable
}

/**
* Build the message.
* Get the message envelope.
*
* @return $this
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function build()
public function envelope()
{
return $this->view('view.name');
return new Envelope(
subject: '{{ subject }}',
);
}

/**
* 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 [];
}
}
34 changes: 30 additions & 4 deletions src/Illuminate/Foundation/Console/stubs/markdown-mail.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace {{ namespace }};
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 {{ class }} extends Mailable
Expand All @@ -22,12 +24,36 @@ class {{ class }} extends Mailable
}

/**
* Build the message.
* Get the message envelope.
*
* @return $this
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function build()
public function envelope()
{
return $this->markdown('{{ view }}');
return new Envelope(
subject: '{{ subject }}',
);
}

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

/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
}
17 changes: 17 additions & 0 deletions src/Illuminate/Mail/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,21 @@ public function attachTo($mail)
fn ($data) => $mail->attachData($data(), $this->as, ['mime' => $this->mime])
);
}

/**
* Determine if the given attachment is equivalent to this attachment.
*
* @param \Illuminate\Mail\Attachment $attachment
* @return bool
*/
public function isEquivalent(Attachment $attachment)
{
return $this->attachWith(
fn ($path) => [$path, ['as' => $this->as, 'mime' => $this->mime]],
fn ($data) => [$data(), ['as' => $this->as, 'mime' => $this->mime]],
) === $attachment->attachWith(
fn ($path) => [$path, ['as' => $attachment->as, 'mime' => $attachment->mime]],
fn ($data) => [$data(), ['as' => $attachment->as, 'mime' => $attachment->mime]],
);
}
}
Loading