First commit

This commit is contained in:
Saufi
2026-05-18 08:56:23 +08:00
commit fd3d3a4d2b
147 changed files with 22099 additions and 0 deletions

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

@@ -0,0 +1,55 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Builder;
class AuditLog extends Model
{
// Audit log adalah append-only — tiada updated_at
const UPDATED_AT = null;
protected $fillable = [
'user_id',
'event',
'auditable_type',
'auditable_id',
'old_values',
'new_values',
'description',
'ip_address',
'user_agent',
];
protected $casts = [
'old_values' => 'array',
'new_values' => 'array',
];
// === Relationships ===
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
// === Scopes ===
public function scopeForModel(Builder $query, string $type, int $id): Builder
{
return $query->where('auditable_type', $type)
->where('auditable_id', $id);
}
public function scopeByEvent(Builder $query, string $event): Builder
{
return $query->where('event', $event);
}
public function scopeRecent(Builder $query, int $days = 30): Builder
{
return $query->where('created_at', '>=', now()->subDays($days));
}
}