feat: implement system-wide activity logging with database persistence, repository patterns, and admin controller access.
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user