4
4
5
5
namespace Stackkit \LaravelDatabaseEmails ;
6
6
7
+ use Closure ;
7
8
use Exception ;
8
9
use Carbon \Carbon ;
10
+ use Illuminate \Database \Eloquent \Builder ;
9
11
use Illuminate \Database \Eloquent \Model ;
12
+ use Illuminate \Database \Eloquent \Prunable ;
10
13
11
14
/**
12
15
* @property $id
15
18
* @property $from
16
19
* @property $cc
17
20
* @property $bcc
21
+ * @property $reply_to
18
22
* @property $subject
19
23
* @property $view
20
24
* @property $variables
33
37
class Email extends Model
34
38
{
35
39
use HasEncryptedAttributes;
40
+ use Prunable;
36
41
37
42
/**
38
43
* The table in which the e-mails are stored.
@@ -48,6 +53,8 @@ class Email extends Model
48
53
*/
49
54
protected $ guarded = [];
50
55
56
+ public static ?Closure $ pruneQuery = null ;
57
+
51
58
/**
52
59
* Compose a new e-mail.
53
60
*
@@ -190,6 +197,26 @@ public function getBccAttribute()
190
197
return $ this ->bcc ;
191
198
}
192
199
200
+ /**
201
+ * Get the e-mail reply-to addresses.
202
+ *
203
+ * @return array|string
204
+ */
205
+ public function getReplyTo ()
206
+ {
207
+ return $ this ->reply_to ;
208
+ }
209
+
210
+ /**
211
+ * Get the e-mail reply-to addresses.
212
+ *
213
+ * @return array|string
214
+ */
215
+ public function getReplyToAttribute ()
216
+ {
217
+ return $ this ->reply_to ;
218
+ }
219
+
193
220
/**
194
221
* Get the e-mail subject.
195
222
*
@@ -388,6 +415,16 @@ public function hasBcc(): bool
388
415
return strlen ($ this ->getRawDatabaseValue ('bcc ' )) > 0 ;
389
416
}
390
417
418
+ /**
419
+ * Determine if the e-mail should sent with reply-to.
420
+ *
421
+ * @return bool
422
+ */
423
+ public function hasReplyTo (): bool
424
+ {
425
+ return strlen ($ this ->getRawDatabaseValue ('reply_to ' ) ?: '' ) > 0 ;
426
+ }
427
+
391
428
/**
392
429
* Determine if the e-mail is scheduled to be sent later.
393
430
*
@@ -520,4 +557,25 @@ public function getRawDatabaseValue(string $key = null, $default = null)
520
557
521
558
return $ this ->getOriginal ($ key , $ default );
522
559
}
560
+
561
+ /**
562
+ * @param Closure $closure
563
+ * @return void
564
+ */
565
+ public static function pruneWhen (Closure $ closure )
566
+ {
567
+ static ::$ pruneQuery = $ closure ;
568
+ }
569
+
570
+ /**
571
+ * @return Builder
572
+ */
573
+ public function prunable ()
574
+ {
575
+ if (static ::$ pruneQuery ) {
576
+ return (static ::$ pruneQuery )($ this );
577
+ }
578
+
579
+ return $ this ->where ('created_at ' , '< ' , now ()->subMonths (6 ));
580
+ }
523
581
}
0 commit comments