Keep an audit log of who did what, and how they came in

Written from model events, spatie's role events and panel sign-ins, only for
what a person did, with secrets masked; pruned after a year.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 10:08:01 +02:00
parent 9bdbf834f6
commit 1fe1e67773
18 changed files with 744 additions and 1 deletions

46
app/Models/AuditLog.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\MassPrunable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* One thing somebody did. Written by App\Support\Audit\Auditor, never edited.
*/
class AuditLog extends Model
{
use MassPrunable;
public const UPDATED_AT = null;
protected $guarded = [];
protected function casts(): array
{
return [
'changes' => 'array',
'created_at' => 'datetime',
];
}
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return Builder<$this>
*/
public function prunable(): Builder
{
return static::query()->where('created_at', '<', now()->subDays((int) config('audit.retention_days', 365)));
}
}