2026-06-23 10:10:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Modules\History\Models;
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Modules\Client\Models\Client;
|
|
|
|
|
use Database\Factories\HistoryEntryFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class HistoryEntry extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory, SoftDeletes;
|
|
|
|
|
|
2026-07-18 09:34:18 +00:00
|
|
|
protected $fillable = [
|
|
|
|
|
'client_id',
|
|
|
|
|
'type',
|
|
|
|
|
'history_entry_type_id',
|
|
|
|
|
'occurred_at',
|
|
|
|
|
'body',
|
|
|
|
|
'custom_field_definition_id',
|
|
|
|
|
'author_id',
|
|
|
|
|
'updated_by',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'type' => HistoryEntryType::class,
|
|
|
|
|
'occurred_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function isFieldChange(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->type === HistoryEntryType::FieldChange;
|
|
|
|
|
}
|
2026-06-23 10:10:28 +00:00
|
|
|
|
|
|
|
|
public function client(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Client::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 09:34:18 +00:00
|
|
|
public function entryType(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(HistoryType::class, 'history_entry_type_id');
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:10:28 +00:00
|
|
|
public function author(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'author_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updatedBy(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static function newFactory(): HistoryEntryFactory
|
|
|
|
|
{
|
|
|
|
|
return HistoryEntryFactory::new();
|
|
|
|
|
}
|
|
|
|
|
}
|