47 lines
932 B
PHP
47 lines
932 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\Generic;
|
|
use App\Models\Model;
|
|
use App\Models\User;
|
|
|
|
class TableLog extends Model
|
|
{
|
|
protected ?string $table = 'table_logs';
|
|
|
|
protected array $casts = [
|
|
'original_data' => 'array',
|
|
'new_data' => 'array',
|
|
];
|
|
|
|
protected array $fillable = [
|
|
'hashkey',
|
|
'table_name',
|
|
'target_id',
|
|
'original_data',
|
|
'new_data',
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
// Auto-merge accessor
|
|
public function get_full_new_row(): array
|
|
{
|
|
return array_merge($this->original_data ?? [], $this->new_data ?? []);
|
|
}
|
|
|
|
public function data(){
|
|
return $this->get_full_new_row();
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function updater()
|
|
{
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
}
|
|
} |