diff --git a/app/Helpers/EventHelper.php b/app/Helpers/EventHelper.php index 5359588..a3dc286 100644 --- a/app/Helpers/EventHelper.php +++ b/app/Helpers/EventHelper.php @@ -4,7 +4,6 @@ enum EventHelper: string { - case NONE = '0'; case DAY = 'day'; case WEEK = 'week'; case MONTH = 'month'; @@ -13,7 +12,6 @@ enum EventHelper: string public static function labels() : array { return [ - self::NONE->value => 'None', self::DAY->value => 'Daily', self::WEEK->value => 'Weekly', self::MONTH->value => 'Monthly', diff --git a/app/Http/Controllers/EventController.php b/app/Http/Controllers/EventController.php index 8acac4c..d556839 100644 --- a/app/Http/Controllers/EventController.php +++ b/app/Http/Controllers/EventController.php @@ -52,9 +52,9 @@ public function store(Request $request) 'start_date' => 'required|date_format:Y-m-d H:i|after_or_equal:today', 'end_date' => 'required|date_format:Y-m-d H:i|after_or_equal:start_date', 'event_type' => 'integer', - 'recurrence_interval' => 'nullable|integer', - 'recurrence_unit' => 'nullable|string|max:255', - 'recurrence_end_date' => 'nullable|date_format:Y-m-d H:i|after_or_equal:end_date', + 'recurrence_interval' => 'required_if:event_type,1|integer', + 'recurrence_unit' => 'required_if:event_type,1|string|max:255|not_in:0', + 'recurrence_end_date' => 'required_if:event_type,1|date_format:Y-m-d H:i|after_or_equal:end_date', 'image' => 'nullable|image|mimes:jpeg,jpg,png|max:2048', ]); @@ -143,9 +143,9 @@ public function update(Request $request, Event $event) 'start_date' => 'required|date_format:Y-m-d H:i|after_or_equal:today', 'end_date' => 'required|date_format:Y-m-d H:i|after_or_equal:start_date', 'event_type' => 'integer', - 'recurrence_interval' => 'nullable|integer', - 'recurrence_unit' => 'nullable|string|max:255', - 'recurrence_end_date' => 'nullable|date_format:Y-m-d H:i|after_or_equal:end_date', + 'recurrence_interval' => 'required_if:event_type,1|integer', + 'recurrence_unit' => 'required_if:event_type,1|string|max:255|not_in:0', + 'recurrence_end_date' => 'required_if:event_type,1|date_format:Y-m-d H:i|after_or_equal:end_date', 'image' => 'nullable|image|mimes:jpeg,jpg,png|max:2048', ]); @@ -218,6 +218,11 @@ public function destroy(Event $event) { $this->authorize('destroy', $event); + // Delete the old image if it exists + if ($event->image && $event->parent()->isEmpty()) { + Storage::disk('public')->delete('banners/' . $event->image); + } + $event->delete(); $event->children()->delete(); diff --git a/resources/views/events/create.blade.php b/resources/views/events/create.blade.php index bda1ce2..0667101 100644 --- a/resources/views/events/create.blade.php +++ b/resources/views/events/create.blade.php @@ -23,7 +23,7 @@
Parent
+ @elseif($event->parent_id != null) + {{ $event->parent->title }} +Id: {{ $event->parent_id }}
@endif