Skip to content

Commit a182fba

Browse files
authored
Merge pull request #344 from ploi/fix/comment-reply-action-arguments
fix: use Filament v4 syntax for comment action arguments
2 parents 85cedf3 + 028a03f commit a182fba

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

app/Livewire/Item/Comment.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Livewire\Item;
44

55
use App\Models\Item;
6+
use App\Models\Comment as CommentModel;
67
use Livewire\Component;
78
use Filament\Actions\Action;
89
use Filament\Support\Colors\Color;
@@ -37,10 +38,9 @@ public function editAction(): Action
3738
->modalDescription('')
3839
->modalIcon('heroicon-o-chat-bubble-left-right')
3940
->fillForm(function (array $arguments): array {
40-
$commentData = $arguments['comment'];
41-
$content = is_array($commentData) ? ($commentData['content'] ?? '') : ($commentData->content ?? '');
41+
$comment = CommentModel::findOrFail($arguments['comment']);
4242
return [
43-
'content' => $content,
43+
'content' => $comment->content,
4444
];
4545
})
4646
->form([
@@ -49,11 +49,7 @@ public function editAction(): Action
4949
])
5050
->link()
5151
->action(function (array $data, array $arguments): void {
52-
// Handle both array and object formats
53-
$commentData = $arguments['comment'];
54-
$commentId = is_array($commentData) ? $commentData['id'] : $commentData->id;
55-
56-
$comment = auth()->user()->comments()->findOrFail($commentId);
52+
$comment = auth()->user()->comments()->findOrFail($arguments['comment']);
5753
$comment->update(['content' => $data['content']]);
5854

5955
$this->redirectRoute('items.show', $comment->item->slug);
@@ -74,15 +70,9 @@ public function replyAction(): Action
7470
])
7571
->link()
7672
->action(function (array $data, array $arguments): void {
77-
// Handle both array and object formats
78-
$commentData = $arguments['comment'];
79-
$commentId = is_array($commentData) ? $commentData['id'] : $commentData->id;
80-
$itemId = is_array($commentData) ? $commentData['item_id'] : $commentData->item_id;
81-
82-
$item = Item::findOrFail($itemId);
83-
$comment = $item->comments()->findOrFail($commentId);
73+
$comment = CommentModel::findOrFail($arguments['comment']);
8474

85-
$item->comments()->create([
75+
$comment->item->comments()->create([
8676
'parent_id' => $comment->id,
8777
'user_id' => auth()->id(),
8878
'content' => $data['content']

resources/views/livewire/item/comment.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ class="md:block inline-flex items-center justify-center py-0.5 px-2 text-xs font
5555

5656
<div class="p-2 flex justify-between gap-2 items-center">
5757
@if($comment->user->is(auth()->user()))
58-
{{ $this->editAction->arguments(['comment' => $comment]) }}
58+
{{ ($this->editAction)(['comment' => $comment->id]) }}
5959
&centerdot;
6060
@endif
6161
@if(!$item->board?->block_comments)
62-
{{ $this->replyAction->arguments(['comment' => $comment]) }}
62+
{{ ($this->replyAction)(['comment' => $comment->id]) }}
6363

6464
&centerdot;
6565
@endif

0 commit comments

Comments
 (0)