Skip to content
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
14 changes: 13 additions & 1 deletion src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,19 @@ public function buildViewData()
}
}

return $data;
return array_merge($data, $this->additionalMessageData());
}

/**
* Get additional meta-data to pass along with the view data.
*
* @return array<string, mixed>
*/
protected function additionalMessageData(): array
{
return [
'__laravel_mailable' => get_class($this),
];
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/Mail/MailMailableDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ class MailMailableDataTest extends TestCase
{
public function testMailableDataIsNotLost()
{
$testData = ['first_name' => 'James'];

$mailable = new MailableStub;

$testData = [
'first_name' => 'James',
'__laravel_mailable' => get_class($mailable),
];

$mailable->build(function ($m) use ($testData) {
$m->view('view', $testData);
});
Expand Down
1 change: 1 addition & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ public function testMailableBuildsViewData()
'first_name' => 'Taylor',
'lastName' => 'Otwell',
'framework' => 'Laravel',
'__laravel_mailable' => get_class($mailable),
];

$this->assertSame($expected, $mailable->buildViewData());
Expand Down