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:
37
app/Http/Resources/AuditLogResource.php
Normal file
37
app/Http/Resources/AuditLogResource.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\AuditLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin AuditLog
|
||||
*/
|
||||
class AuditLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'action' => $this->action,
|
||||
'user' => ['id' => $this->user_id, 'name' => $this->user_name],
|
||||
'via' => $this->via,
|
||||
'api_token_id' => $this->api_token_id,
|
||||
'ip' => $this->ip,
|
||||
'subject' => $this->subject_type ? [
|
||||
'type' => $this->subject_type,
|
||||
'id' => $this->subject_id,
|
||||
'label' => $this->subject_label,
|
||||
] : null,
|
||||
'changes' => $this->changes === null ? null : (object) $this->changes,
|
||||
'created_at' => $this->created_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user