79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Helpdesk\Models;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
final class Comment extends Model
|
|
{
|
|
protected $table = 'helpdesk_comments';
|
|
|
|
/** @var list<string> */
|
|
protected $fillable = [
|
|
'ticket_id',
|
|
'parent_id',
|
|
'user_id',
|
|
'subject',
|
|
'body',
|
|
'body_text',
|
|
'is_internal',
|
|
'guid',
|
|
'unid',
|
|
'replica_id',
|
|
'parent_unid',
|
|
'root_unid',
|
|
'originator_id',
|
|
'sync_sequence',
|
|
'sync_hash',
|
|
'source_system',
|
|
'source_record_id',
|
|
'replicated_at',
|
|
'synced_at',
|
|
'tombstoned_at',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = [
|
|
'is_internal' => 'boolean',
|
|
'sync_sequence' => 'integer',
|
|
'replicated_at' => 'datetime',
|
|
'synced_at' => 'datetime',
|
|
'tombstoned_at' => 'datetime',
|
|
];
|
|
|
|
/** @return BelongsTo<Ticket, Comment> */
|
|
public function ticket(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ticket::class, 'ticket_id');
|
|
}
|
|
|
|
/** @return BelongsTo<Comment, Comment> */
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_id');
|
|
}
|
|
|
|
/** @return HasMany<Comment> */
|
|
public function replies(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id')->oldest();
|
|
}
|
|
|
|
/** @return BelongsTo<User, Comment> */
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
/** @return HasMany<Attachment> */
|
|
public function attachments(): HasMany
|
|
{
|
|
return $this->hasMany(Attachment::class, 'comment_id');
|
|
}
|
|
}
|