Skip to content

Commit 9952959

Browse files
authored
Add message id to logs (#40)
1 parent 38b60e4 commit 9952959

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
/**
9+
* Run the migrations.
10+
*/
11+
public function up(): void
12+
{
13+
Schema::table('logs', function (Blueprint $table) {
14+
$table->string('message_id')->nullable()->index()->after('id');
15+
});
16+
}
17+
18+
/**
19+
* Reverse the migrations.
20+
*/
21+
public function down(): void
22+
{
23+
Schema::table('logs', function (Blueprint $table) {
24+
$table->dropColumn('message_id');
25+
});
26+
}
27+
};

src/Jobs/SendMailJob.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Bus\Queueable;
77
use Illuminate\Contracts\Queue\ShouldQueue;
88
use Illuminate\Foundation\Bus\Dispatchable;
9+
use Illuminate\Mail\SentMessage;
910
use Illuminate\Queue\InteractsWithQueue;
1011
use Illuminate\Queue\SerializesModels;
1112
use Illuminate\Support\Facades\Mail;
@@ -77,7 +78,14 @@ public function handle(): void
7778
*/
7879
protected function send(): void
7980
{
80-
$sendMail = fn (?GenericMailDto $override = null) => Mail::send(new GenericMail($override ?: $this->genericMailDto));
81+
$sendMail = function (?GenericMailDto $override = null) {
82+
$sent = Mail::send(new GenericMail($override ?: $this->genericMailDto));
83+
84+
if ($sent instanceof SentMessage) {
85+
$this->log->message_id = $sent->getMessageId();
86+
$this->log->save();
87+
}
88+
};
8189

8290
if ($this->sendingMiddleware) {
8391
$middleware = unserialize($this->sendingMiddleware)->getClosure();

src/Models/Log.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Log extends Model
6666
'status',
6767
'trigger',
6868
'subject',
69+
'message_id',
6970
'cc',
7071
'bcc',
7172
'sender',

0 commit comments

Comments
 (0)