Skip to content

Commit 38b60e4

Browse files
authored
Add logs events table (#41)
1 parent 8dc2d9b commit 38b60e4

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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::create('log_events', function (Blueprint $table) {
14+
$table->uuid('id')->primary();
15+
$table->foreignUuid('log_id')->index()->constrained()->cascadeOnDelete();
16+
$table->string('name');
17+
$table->timestamps();
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*/
24+
public function down(): void
25+
{
26+
Schema::dropIfExists('log_events');
27+
}
28+
};

src/Models/Log.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @property \MailCarrier\Enums\LogStatus $status
2222
* @property string|null $trigger
2323
* @property string|null $subject
24+
* @property string|null $message_id
2425
* @property \MailCarrier\Dto\ContactDto $sender
2526
* @property \MailCarrier\Dto\ContactDto|null $replyTo
2627
* @property \Illuminate\Support\Collection<MailCarrier\Dto\ContactDto>|null $cc
@@ -37,6 +38,7 @@
3738
* @property array|null $metadata
3839
* @property-read \MailCarrier\Models\Template|null $template
3940
* @property-read \Illuminate\Database\Eloquent\Collection<int, \MailCarrier\Models\Attachment> $attachments
41+
* @property-read \Illuminate\Database\Eloquent\Collection<int, \MailCarrier\Models\LogEvent> $events
4042
*/
4143
class Log extends Model
4244
{
@@ -119,6 +121,14 @@ public function attachments(): HasMany
119121
return $this->hasMany(Attachment::class);
120122
}
121123

124+
/**
125+
* Get the log's events.
126+
*/
127+
public function events(): HasMany
128+
{
129+
return $this->hasMany(LogEvent::class);
130+
}
131+
122132
/**
123133
* Get the prunable model query.
124134
*/

src/Models/LogEvent.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace MailCarrier\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use MailCarrier\Models\Concerns\IsUuid;
9+
10+
/**
11+
* @property string $id
12+
* @property string $log_id
13+
* @property string $name
14+
* @property \Carbon\CarbonImmutable $created_at
15+
* @property \Carbon\CarbonImmutable $updated_at
16+
* @property-read \MailCarrier\Models\Log $log
17+
*/
18+
class LogEvent extends Model
19+
{
20+
use HasFactory;
21+
use IsUuid;
22+
23+
/**
24+
* Indicates if the IDs are auto-incrementing.
25+
*/
26+
public $incrementing = false;
27+
28+
/**
29+
* The data type of the auto-incrementing ID.
30+
*/
31+
protected $keyType = 'string';
32+
33+
/**
34+
* The attributes that are mass assignable.
35+
*
36+
* @var array<int, string>
37+
*/
38+
protected $fillable = [
39+
'log_id',
40+
'name',
41+
];
42+
43+
/**
44+
* Get the log that owns the event.
45+
*/
46+
public function log(): BelongsTo
47+
{
48+
return $this->belongsTo(Log::class);
49+
}
50+
}

0 commit comments

Comments
 (0)