|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Models; |
| 4 | + |
| 5 | +use Illuminate\Database\Eloquent\Concerns\HasUuids; |
| 6 | +use Illuminate\Database\Eloquent\Model; |
| 7 | +use Illuminate\Database\Eloquent\Relations\BelongsTo; |
| 8 | + |
| 9 | +/** |
| 10 | + * One row per tenant-scoped mutation. Append-only; never deleted. |
| 11 | + * |
| 12 | + * Created by the AuditLogObserver when a Registry / Tenant is |
| 13 | + * created / updated / deleted (observer lives in |
| 14 | + * App\Observers\AuditLogObserver, registered in AppServiceProvider). |
| 15 | + * |
| 16 | + * @property string $id |
| 17 | + * @property string $tenant_id |
| 18 | + * @property int|null $user_id |
| 19 | + * @property string $action create|update|delete |
| 20 | + * @property string $target_type |
| 21 | + * @property string $target_id |
| 22 | + * @property array<string,mixed>|null $before |
| 23 | + * @property array<string,mixed>|null $after |
| 24 | + */ |
| 25 | +class AuditLogEntry extends Model |
| 26 | +{ |
| 27 | + use HasUuids; |
| 28 | + |
| 29 | + /** |
| 30 | + * Audit log is append-only: it has no `updated_at` semantic; the |
| 31 | + * record is immutable from creation. We still let Laravel manage |
| 32 | + * `created_at` via timestamps but never expose an update path. |
| 33 | + */ |
| 34 | + public const UPDATED_AT = null; |
| 35 | + |
| 36 | + protected $fillable = [ |
| 37 | + 'tenant_id', 'user_id', 'action', |
| 38 | + 'target_type', 'target_id', |
| 39 | + 'before', 'after', |
| 40 | + ]; |
| 41 | + |
| 42 | + /** @var array<string,string> */ |
| 43 | + protected $casts = [ |
| 44 | + 'before' => 'array', |
| 45 | + 'after' => 'array', |
| 46 | + ]; |
| 47 | + |
| 48 | + /** @return BelongsTo<Tenant, $this> */ |
| 49 | + public function tenant(): BelongsTo |
| 50 | + { |
| 51 | + return $this->belongsTo(Tenant::class); |
| 52 | + } |
| 53 | + |
| 54 | + /** @return BelongsTo<User, $this> */ |
| 55 | + public function user(): BelongsTo |
| 56 | + { |
| 57 | + return $this->belongsTo(User::class); |
| 58 | + } |
| 59 | +} |
0 commit comments