22
33namespace Buildcode \LaravelDatabaseEmails \Decorators ;
44
5+ use Buildcode \LaravelDatabaseEmails \Config ;
56use Buildcode \LaravelDatabaseEmails \Email ;
67
78class PrepareEmail implements EmailDecorator
@@ -12,21 +13,48 @@ public function __construct(Email $email)
1213 {
1314 $ this ->email = $ email ;
1415
15- $ email ->body = view ($ email ->getView (), $ email ->getVariables ());
16+ if ($ email ->hasCc ()) {
17+ if (!is_array ($ email ->cc )) {
18+ $ email ->cc = [$ email ->cc ];
19+ }
1620
17- $ email ->variables = json_encode ($ email ->getVariables ());
21+ if (Config::testing ()) {
22+ $ email ->cc = array_map (function () {
23+ return Config::testEmailAddress ();
24+ }, $ email ->cc );
25+ }
1826
19- if ($ email ->hasScheduledDate ()) {
20- $ email ->scheduled_at = $ email ->getScheduledDateAsCarbon ()->toDateTimeString ();
27+ $ email ->cc = json_encode ($ email ->cc );
28+ }
29+
30+ if ($ email ->hasBcc ()) {
31+ if (!is_array ($ email ->bcc )) {
32+ $ email ->bcc = [$ email ->bcc ];
33+ }
34+
35+ if (Config::testing ()) {
36+ $ email ->bcc = array_map (function () {
37+ return Config::testEmailAddress ();
38+ }, $ email ->bcc );
39+ }
40+
41+ $ email ->bcc = json_encode ($ email ->bcc );
2142 }
2243
23- $ this ->email ->encrypted = config ('laravel-database-emails.encrypt ' , false );
2444
25- $ test = config ( ' laravel-database-emails.testing.enabled ' , false );
45+ $ email -> body = view ( $ email -> getView (), $ email -> hasVariables () ? $ email -> getVariables () : [])-> render ( );
2646
27- if ($ test ()) {
28- $ email ->recipient = config ('laravel-database-emails.testing.email ' );
47+ $ email ->variables = json_encode ($ email ->getVariables ());
48+
49+ if ($ email ->isScheduled ()) {
50+ $ email ->scheduled_at = $ email ->getScheduledDateAsCarbon ()->toDateTimeString ();
2951 }
52+
53+ if (Config::testing ()) {
54+ $ email ->recipient = Config::testEmailAddress ();
55+ }
56+
57+ $ this ->email ->encrypted = Config::encryptEmails ();
3058 }
3159
3260 public function getEmail ()
0 commit comments