51 lines
1.0 KiB
PHP
51 lines
1.0 KiB
PHP
<?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,
|
|
};
|
|
}
|
|
}
|