55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Helpdesk\Models;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
final class Comment extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'helpdesk_comments';
|
|
|
|
/** @var list<string> */
|
|
protected $fillable = ['ticket_id', 'parent_id', 'user_id', 'body', 'is_internal'];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = ['is_internal' => 'boolean'];
|
|
|
|
/** @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');
|
|
}
|
|
}
|