Skip to content

Commit 85e36c4

Browse files
authored
Change CleanEmails command to delete individual models
This allows events to be fired when an email is deleted. Also uses the custom defined model.
1 parent d0d300b commit 85e36c4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Console/CleanEmails.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ public function handle()
2020

2121
$cutOffDate = Carbon::now()->subDay($maxAgeInDays)->format('Y-m-d H:i:s');
2222

23-
$amountDeleted = InboundEmail::where('created_at', '<', $cutOffDate)->delete();
23+
/** @var InboundEmail $modelClass */
24+
$modelClass = config('mailbox.model');
25+
26+
$models = $modelClass::where('created_at', '<', $cutOffDate)->get();
27+
28+
$models->each->delete();
29+
30+
$amountDeleted = $models->count();
2431

2532
$this->info("Deleted {$amountDeleted} record(s) from the Mailbox logs.");
2633

0 commit comments

Comments
 (0)