feat: implement system-wide activity logging with database persistence, repository patterns, and admin controller access.

This commit is contained in:
pbao9
2026-05-16 20:01:52 +07:00
parent 8a115c5175
commit 551c90d60b
44 changed files with 845 additions and 33 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ActivityLog extends Model
{
public $timestamps = false;
protected $table = 'activity_logs';
protected $fillable = [
'log_name',
'event',
'description',
'subject_type',
'subject_id',
'causer_type',
'causer_id',
'causer_name',
'old_values',
'new_values',
'ip_address',
'user_agent',
'created_at',
];
protected $casts = [
'old_values' => 'array',
'new_values' => 'array',
'created_at' => 'datetime',
];
protected static function booting(): void
{
static::creating(function (self $model) {
$model->created_at = now();
});
}
public function causer()
{
return match ($this->causer_type) {
'admin' => $this->belongsTo(User::class, 'causer_id'),
'customer' => $this->belongsTo(Customer::class, 'causer_id'),
default => null,
};
}
}