-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathSupportTicket.php
More file actions
70 lines (60 loc) · 1.57 KB
/
SupportTicket.php
File metadata and controls
70 lines (60 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace App\Models;
use App\Models\SupportTicket\Reply;
use App\SupportTicket\Status;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
class SupportTicket extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'user_id',
'mask',
'subject',
'message',
'status',
'product',
'issue_type',
'metadata',
];
protected function casts(): array
{
return [
'status' => Status::class,
'metadata' => 'array',
];
}
protected static function booted()
{
static::creating(function ($ticket) {
if (is_null($ticket->mask)) {
// @TODO Generate a unique mask for the ticket
$ticket->mask = uniqid('ticket_');
}
});
}
public function getRouteKeyName(): string
{
return 'mask';
}
public function replies(): HasMany
{
return $this->hasMany(Reply::class)
->orderBy('created_at', 'desc');
}
public function pinnedNote(): HasOne
{
return $this->hasOne(Reply::class)
->where('note', true)
->where('pinned', true)
->latestOfMany();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}