From fa3d5c16d005b5e664692197fa5509844aa7b177 Mon Sep 17 00:00:00 2001 From: Jaton David Date: Tue, 17 Dec 2024 16:35:54 +0100 Subject: [PATCH] Delete media in folder --- app/Http/Controllers/ChatController.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index da8d3df..192e721 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -276,10 +276,22 @@ public function deleteMessage($discussionId, $messageId) if (Message::find($message->id + 10000000)) { $capsule = Message::where('id', $messageId + 10000000)->where('chat_id', $discussionId)->first(); + if ($message->media_url) { + $mediaPath = public_path('source/assets/media/' . $message->media_url); + if (file_exists($mediaPath)) { + unlink($mediaPath); + } + } $capsule->delete(); $message->delete(); } else{ + if ($message->media_url) { + $mediaPath = public_path("/source/media/" . $message->media_url); + if (file_exists($mediaPath)) { + unlink($mediaPath); + } + } $message->delete(); }