-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathTicketRepliesWidget.php
More file actions
64 lines (49 loc) · 1.68 KB
/
TicketRepliesWidget.php
File metadata and controls
64 lines (49 loc) · 1.68 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
<?php
namespace App\Filament\Resources\SupportTicketResource\Widgets;
use App\Models\SupportTicket\Reply;
use App\Notifications\SupportTicketReplied;
use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;
class TicketRepliesWidget extends Widget
{
protected string $view = 'filament.resources.support-ticket-resource.widgets.ticket-replies';
public ?Model $record = null;
public string $newMessage = '';
public bool $isNote = false;
protected int|string|array $columnSpan = 'full';
protected function getListeners(): array
{
return [];
}
public function sendReply(): void
{
$this->validate([
'newMessage' => ['required', 'string', 'max:5000'],
]);
$reply = $this->record->replies()->create([
'user_id' => auth()->id(),
'message' => $this->newMessage,
'note' => $this->isNote,
]);
if (! $this->isNote && $this->record->user_id !== auth()->id()) {
$this->record->user->notify(new SupportTicketReplied($this->record, $reply));
}
$this->newMessage = '';
$this->isNote = false;
}
public function togglePin(int $replyId): void
{
$reply = Reply::where('support_ticket_id', $this->record->id)
->where('id', $replyId)
->where('note', true)
->firstOrFail();
if ($reply->pinned) {
$reply->update(['pinned' => false]);
} else {
Reply::where('support_ticket_id', $this->record->id)
->where('pinned', true)
->update(['pinned' => false]);
$reply->update(['pinned' => true]);
}
}
}