-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathSupportTicket.php
More file actions
55 lines (46 loc) · 1.23 KB
/
SupportTicket.php
File metadata and controls
55 lines (46 loc) · 1.23 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
<?php
namespace App\Models;
use App\Models\SupportTicket\Reply;
use App\SupportTicket\Status;
use Illuminate\Database\Eloquent\Casts\Attribute;
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\SoftDeletes;
class SupportTicket extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'user_id',
'mask',
'subject',
'message',
'status',
];
protected $casts = [
'status' => Status::class,
];
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 user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}