mandant-crm/backend/app/Modules/History/Models/HistoryEntry.php
Tim Stollberg f0bb80707a feat(backend): commit uncommitted CustomField, dynamic HistoryType, and Import modules
Mirrors the frontend catch-up in 570f17e: a substantial amount of
finished-but-never-committed backend work had accumulated locally.

- New CustomField module: admin-managed field definitions per client,
  reorderable, typed values stored per client (backing the frontend's
  ClientCustomFieldCard + settings/fields page)
- History entries switch from a hardcoded type enum to a dynamic,
  admin-managed HistoryType module (reorderable, backing
  settings/history-types)
- New Import module: CSV client import (backing settings/import)
- Clients table gains soft deletes (deleted_at)
- Supporting factories, seeders, policies, and feature tests for all
  of the above

All 63 backend tests pass locally before this commit.
2026-07-18 16:34:18 +07:00

62 lines
1.4 KiB
PHP

<?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();
}
}