New-Thanasoft/thanasoft-back/app/Models/DocumentStatusHistory.php

45 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DocumentStatusHistory extends Model
{
protected $table = 'document_status_history';
public $timestamps = false; // We are using changed_at
protected $fillable = [
'document_type',
'document_id',
'old_status',
'new_status',
'changed_by',
'changed_at',
'comment',
];
protected $casts = [
'changed_at' => 'datetime',
];
public function user()
{
return $this->belongsTo(User::class, 'changed_by');
}
/**
* Get the parent document model (quote or invoice).
*/
public function document()
{
// define a custom polymorphic relationship or helper if needed
// Since it is an enum, we can't use standard morphTo easily without a map.
// But for now, I will just leave it or maybe add a helper.
// Standard Laravel morph expects 'document_type' to be the class name.
// Here it is 'quote' or 'invoice'.
// We can use morphMap in AppServiceProvider to map 'quote' => Quote::class.
return $this->morphTo(__FUNCTION__, 'document_type', 'document_id');
}
}