Files
new_raffles/Modules/PMS/app/Models/Ticket.php
2025-07-27 17:40:56 +05:45

141 lines
4.4 KiB
PHP

<?php
namespace Modules\PMS\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Document;
use Modules\Admin\Models\Department;
use Modules\Employee\Models\Employee;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Ticket extends Model
{
/**
* The attributes that are mass assignable.
*/
protected $table = 'tbl_tickets';
// protected $fillable = ['subject', 'employee_id', 'department_id', 'assign_group_id', 'project_id', 'desc', 'file', 'ticket_type', 'status', 'priority'];
protected $guarded = [];
protected $appends = ['status_name', 'priority_status', 'ticket_type'];
const STATUS = [
10 => 'Pending',
11 => 'Approved',
12 => 'Rejected',
];
const PRIORITY = [
10 => 'High',
11 => 'Meduim',
12 => 'Low',
];
const TICKET_TYPE = [
11 => 'Management',
12 => 'Boxes',
13 => 'Assets'
];
protected function statusName(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
switch ($attributes['status']) {
case '10':
$color = 'danger';
break;
case '11':
$color = 'info';
break;
case '12':
$color = 'primary';
break;
case '13':
$color = 'warning';
break;
case '14':
$color = 'success';
break;
default:
$color = 'light';
break;
}
return collect([
'status' => self::STATUS[$attributes['status']],
'color' => $color]);
},
set: fn($value) => $value,
);
}
protected function priorityStatus(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
switch ($attributes['priority']) {
case '10':
return '<span class="badge bg-danger">' . self::PRIORITY[$attributes['priority']] . '</span>';
break;
case '11':
return '<span class="badge bg-info">' . self::PRIORITY[$attributes['priority']] . '</span>';
break;
case '12':
return '<span class="badge bg-primary">' . self::PRIORITY[$attributes['priority']] . '</span>';
break;
default:
# code...
break;
}
},
set: fn($value) => $value,
);
}
protected function ticketType(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
switch ($attributes['ticket_type']) {
case '11':
return '<span class="badge bg-info">' . self::TICKET_TYPE[$attributes['ticket_type']] . '</span>';
break;
case '12':
return '<span class="badge bg-info">' . self::TICKET_TYPE[$attributes['ticket_type']] . '</span>';
break;
case '13':
return '<span class="badge bg-info">' . self::TICKET_TYPE[$attributes['ticket_type']] . '</span>';
break;
default:
# code...
break;
}
},
set: fn($value) => $value,
);
}
public function project()
{
return $this->belongsTo(Project::class, 'project_id');
}
public function employee()
{
return $this->belongsTo(Employee::class, 'employee_id');
}
public function department()
{
return $this->belongsTo(Department::class, 'department_id')->withDefault();
}
public function documents(): MorphMany
{
return $this->morphMany(Document::class, 'documentable');
}
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
}