Files

26 lines
698 B
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Models\AuditLog;
use Illuminate\Http\JsonResponse;
abstract class Controller
{
protected function ok(mixed $data = null, string $message = 'ok', int $status = 200): JsonResponse
{
return response()->json(['message' => $message, 'data' => $data], $status);
}
protected function audit($actor, string $action, ?object $model, string $summary): void
{
AuditLog::query()->create([
'actor_id' => $actor?->id,
'action' => $action,
'subject_type' => $model ? $model::class : null,
'subject_id' => $model->id ?? null,
'summary' => $summary,
]);
}
}