vernova/AuditLog.php
2026-07-26 19:58:27 +03:30

50 lines
974 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AuditLog extends Model
{
use HasFactory;
public const UPDATED_AT = null;
protected $fillable = [
'user_id',
'tenant_id',
'model_type',
'model_id',
'action',
'old_values',
'new_values',
'ip_address',
'user_agent',
'url',
'method',
];
protected $casts = [
'old_values' => 'array',
'new_values' => 'array',
];
public function user()
{
return $this->belongsTo(User::class);
}
/**
* Get the auditable model (polymorphic-like relationship using model_type/model_id).
*/
public function subject()
{
if ($this->model_type && class_exists($this->model_type)) {
return $this->morphTo(null, 'model_type', 'model_id');
}
return null;
}
}