Skip to content

Commit

Permalink
add mailable class metadata to viewdata (#53042)
Browse files Browse the repository at this point in the history
Co-authored-by: TobMoeller <[email protected]>
  • Loading branch information
TobMoeller and TobMoeller authored Oct 7, 2024
1 parent ffee111 commit bc5bd66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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

0 comments on commit bc5bd66

Please sign in to comment.