Skip to content

Commit bc5bd66

Browse files
TobMoellerTobMoeller
andauthored
add mailable class metadata to viewdata (#53042)
Co-authored-by: TobMoeller <[email protected]>
1 parent ffee111 commit bc5bd66

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/Illuminate/Mail/Mailable.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,19 @@ public function buildViewData()
352352
}
353353
}
354354

355-
return $data;
355+
return array_merge($data, $this->additionalMessageData());
356+
}
357+
358+
/**
359+
* Get additional meta-data to pass along with the view data.
360+
*
361+
* @return array<string, mixed>
362+
*/
363+
protected function additionalMessageData(): array
364+
{
365+
return [
366+
'__laravel_mailable' => get_class($this),
367+
];
356368
}
357369

358370
/**

tests/Mail/MailMailableDataTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ class MailMailableDataTest extends TestCase
99
{
1010
public function testMailableDataIsNotLost()
1111
{
12-
$testData = ['first_name' => 'James'];
13-
1412
$mailable = new MailableStub;
13+
14+
$testData = [
15+
'first_name' => 'James',
16+
'__laravel_mailable' => get_class($mailable),
17+
];
18+
1519
$mailable->build(function ($m) use ($testData) {
1620
$m->view('view', $testData);
1721
});

tests/Mail/MailMailableTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ public function testMailableBuildsViewData()
592592
'first_name' => 'Taylor',
593593
'lastName' => 'Otwell',
594594
'framework' => 'Laravel',
595+
'__laravel_mailable' => get_class($mailable),
595596
];
596597

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

0 commit comments

Comments
 (0)