From 6ce3c7b6481d49cfd2552748dcdbadec1407f4f8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 2 Aug 2024 18:48:10 +0200 Subject: [PATCH] fix: updating events files --- app/Http/Controllers/API/EventController.php | 14 +++++++------- app/Http/Controllers/EventController.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/API/EventController.php b/app/Http/Controllers/API/EventController.php index 9c5bed7..94b7b20 100644 --- a/app/Http/Controllers/API/EventController.php +++ b/app/Http/Controllers/API/EventController.php @@ -70,7 +70,7 @@ public function store(Request $request) $storedPath = $image->storeAs('banners', $imageName, 'public'); // Check if the image was successfully uploaded - if ($storedPath && !Storage::disk('public')->exists($storedPath)) { + if (!$storedPath && !Storage::disk('public')->exists($storedPath)) { return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput(); } @@ -145,24 +145,24 @@ public function update(Request $request, Event $event) // Get image dimensions list($width, $height) = getimagesize($imagePath); - if ($width / $height != 16 / 9) { + if (round($width / $height, 2) != round(16 / 9, 2)) { return back()->withErrors(['image' => 'Image must be in 16:9 aspect ratio.']); } // Delete the old image if it exists if ($event->image) { - Storage::disk('public')->delete('images/' . $event->image); + Storage::disk('public')->delete('banners/' . $event->image); } // Store the new image - $image->storeAs('images', $imageName, 'public'); + $image->storeAs('banners', $imageName, 'public'); // Check if the image was successfully uploaded - if (!Storage::disk('public')->exists('images/' . $imageName)) { + if (!Storage::disk('public')->exists('banners/' . $imageName)) { return back()->withErrors(['image' => 'Failed to upload the image.']); } - $imageURL = asset('storage/images/' . $imageName); + $imageURL = asset('storage/banners/' . $imageName); $event->image = $imageURL; } @@ -177,7 +177,7 @@ public function update(Request $request, Event $event) 'recurrence_interval' => $request->input('event_type') == '0' ? null : $request->input('recurrence_interval'), 'recurrence_unit' => $request->input('event_type') == '0' ? null : $request->input('recurrence_unit'), 'recurrence_end_date' => $request->input('event_type') == '0' ? null : $request->input('recurrence_end_date'), - 'image' => $imageURL, + 'image' => $imageName, ]); $event->user()->associate($user); diff --git a/app/Http/Controllers/EventController.php b/app/Http/Controllers/EventController.php index e8e97ca..34116b9 100644 --- a/app/Http/Controllers/EventController.php +++ b/app/Http/Controllers/EventController.php @@ -74,7 +74,7 @@ public function store(Request $request) $storedPath = $image->storeAs('banners', $imageName, 'public'); // Check if the image was successfully uploaded - if ($storedPath && !Storage::disk('public')->exists($storedPath)) { + if (!$storedPath && !Storage::disk('public')->exists($storedPath)) { return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput(); } @@ -158,24 +158,24 @@ public function update(Request $request, Event $event) // Get image dimensions list($width, $height) = getimagesize($imagePath); - if ($width / $height != 16 / 9) { + if (round($width / $height, 2) != round(16 / 9, 2)) { return back()->withErrors(['image' => 'Image must be in 16:9 aspect ratio.']); } // Delete the old image if it exists if ($event->image) { - Storage::disk('public')->delete('images/' . $event->image); + Storage::disk('public')->delete('banners/' . $event->image); } // Store the new image - $image->storeAs('images', $imageName, 'public'); + $image->storeAs('banners', $imageName, 'public'); // Check if the image was successfully uploaded - if (!Storage::disk('public')->exists('images/' . $imageName)) { + if (!Storage::disk('public')->exists('banners/' . $imageName)) { return back()->withErrors(['image' => 'Failed to upload the image.']); } - $imageURL = asset('storage/images/' . $imageName); + $imageURL = asset('storage/banners/' . $imageName); $event->image = $imageURL; } @@ -190,7 +190,7 @@ public function update(Request $request, Event $event) 'recurrence_interval' => $request->input('event_type') == '0' ? null : $request->input('recurrence_interval'), 'recurrence_unit' => $request->input('event_type') == '0' ? null : $request->input('recurrence_unit'), 'recurrence_end_date' => $request->input('event_type') == '0' ? null : $request->input('recurrence_end_date'), - 'image' => $imageURL, + 'image' => $imageName, ]); // Ensure user association