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 @@
- @foreach ($calendars as $calendar) @can('view', $calendar) @@ -31,8 +31,8 @@ @endcan @endforeach - @error('calendar') - {{ $errors->first('calendar') }} + @error('calendar_id') + {{ $errors->first('calendar_id') }} @enderror
@@ -89,21 +89,20 @@
- +
- - +
-
+
diff --git a/resources/views/events/edit.blade.php b/resources/views/events/edit.blade.php index f18e578..726a7fa 100644 --- a/resources/views/events/edit.blade.php +++ b/resources/views/events/edit.blade.php @@ -24,7 +24,7 @@
- @foreach ($calendars as $calendar) @can('view', $calendar) @@ -32,8 +32,8 @@ @endcan @endforeach - @error('calendar') - {{ $errors->first('calendar') }} + @error('calendar_id') + {{ $errors->first('calendar_id') }} @enderror
@@ -93,7 +93,7 @@
- recurrence_interval != 1 ? 'checked' : '' }}> + recurrence_interval == null ? 'checked' : '' }}> @@ -107,7 +107,7 @@
-
+
diff --git a/resources/views/events/index.blade.php b/resources/views/events/index.blade.php index ab422db..4bc3801 100644 --- a/resources/views/events/index.blade.php +++ b/resources/views/events/index.blade.php @@ -41,8 +41,11 @@ {{ \Carbon\Carbon::parse($event->start_date)->format('d-m-Y H:i') }}z {{ \Carbon\Carbon::parse($event->end_date)->format('d-m-Y H:i') }}z - @if ($event->parent_id != null && $event->recurrence_interval != null) - {{ $event->parent->title }} + @if ($event->children->isNotEmpty()) +

Parent

+ @elseif($event->parent_id != null) + {{ $event->parent->title }} +

Id: {{ $event->parent_id }}

@endif @@ -55,7 +58,7 @@ onsubmit="return confirm('Are you sure you want to delete this event? - {{ $event->title }}')"> @method('DELETE') @csrf - + @endcan diff --git a/resources/views/events/show.blade.php b/resources/views/events/show.blade.php index 98cccce..5a93e14 100644 --- a/resources/views/events/show.blade.php +++ b/resources/views/events/show.blade.php @@ -27,7 +27,7 @@
- Recurrence End Date: {{ \Carbon\Carbon::parse($event->recurrence_end_date)->format('F j, Y, H:i') }}z + Recurrence End Date: {{ \Carbon\Carbon::parse($event->recurrence_end_date)->format('F j, Y') }}z
@endif