1 | <?php |
||||
2 | |||||
3 | namespace App\Traits; |
||||
4 | |||||
5 | use Illuminate\Container\Container; |
||||
6 | |||||
7 | /** |
||||
8 | * This trait can be used on a Mailable class to get the mailable's plain text, |
||||
9 | * or for converting to an array that might be returned in an API request. |
||||
10 | */ |
||||
11 | trait ApiMailable |
||||
12 | { |
||||
13 | public function getPlainText() |
||||
14 | { |
||||
15 | return $this->withLocale($this->locale, function () { |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
16 | Container::getInstance()->call([$this, 'build']); |
||||
17 | return $this->buildView()['text']->toHtml(); |
||||
0 ignored issues
–
show
It seems like
buildView() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
18 | }); |
||||
19 | } |
||||
20 | |||||
21 | public function toArray() |
||||
22 | { |
||||
23 | return $this->withLocale($this->locale, function () { |
||||
24 | Container::getInstance()->call([$this, 'build']); |
||||
25 | |||||
26 | $mail = $this; |
||||
27 | return [ |
||||
28 | 'from' => $mail->from, |
||||
29 | 'to' => $mail->to, |
||||
30 | 'cc' => $mail->cc, |
||||
31 | 'bcc' => $mail->bcc, |
||||
32 | 'subject' => $mail->subject, |
||||
33 | 'body' => $mail->getPlainText(), |
||||
34 | ]; |
||||
35 | }); |
||||
36 | } |
||||
37 | } |
||||
38 |