migrant-web/app/Models/SupportTicket.php

54 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SupportTicket extends Model
{
use HasFactory;
protected $fillable = [
'ticket_number',
'user_id',
'reason_id',
'worker_id',
'subject',
'description',
'status',
'priority',
];
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
public function reason()
{
return $this->belongsTo(ReportReason::class, 'reason_id');
}
public function worker()
{
return $this->belongsTo(Worker::class, 'worker_id');
}
public function replies()
{
return $this->hasMany(SupportTicketReply::class, 'support_ticket_id');
}
/**
* Get the creator of the ticket (either User/Employer or Worker).
*/
public function creator()
{
if ($this->user_id) {
return $this->user;
}
return $this->worker;
}
}