68 lines
1.4 KiB
PHP
68 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Ticket extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public const StatusOpen = 'open';
|
|
|
|
public const StatusProcessing = 'processing';
|
|
|
|
public const StatusResolved = 'resolved';
|
|
|
|
public const StatusClosed = 'closed';
|
|
|
|
public const STATUSES = [
|
|
self::StatusOpen,
|
|
self::StatusProcessing,
|
|
self::StatusResolved,
|
|
self::StatusClosed,
|
|
];
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'ticket_category_id',
|
|
'assigned_user_id',
|
|
'title',
|
|
'content',
|
|
'status',
|
|
'last_replied_at',
|
|
'closed_at',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TicketCategory::class, 'ticket_category_id');
|
|
}
|
|
|
|
public function assignedUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'assigned_user_id');
|
|
}
|
|
|
|
public function messages(): HasMany
|
|
{
|
|
return $this->hasMany(TicketMessage::class);
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'last_replied_at' => 'datetime',
|
|
'closed_at' => 'datetime',
|
|
];
|
|
}
|
|
}
|