33namespace App \Livewire \Item ;
44
55use App \Models \Item ;
6+ use App \Models \Comment as CommentModel ;
67use Livewire \Component ;
78use Filament \Actions \Action ;
89use 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 ' ]
0 commit comments