mandant-crm/backend/app/Modules/History/Models/HistoryEntry.php

63 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?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;
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;
}
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
public function entryType(): BelongsTo
{
return $this->belongsTo(HistoryType::class, 'history_entry_type_id');
}
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();
}
}