country = request()->route('country'); if ($this->event) { $this->from = $this->event->from->format('Y-m-d\TH:i'); $this->to = $this->event->to->format('Y-m-d\TH:i'); $this->venue_id = $this->event->venue_id; $this->link = $this->event->link; } else { // Set default start time to next Monday at 09:00 $nextMonday = now()->next('Monday')->setTime(9, 0); $this->from = $nextMonday->format('Y-m-d\TH:i'); $this->to = $nextMonday->copy()->addHours(3)->format('Y-m-d\TH:i'); } } public function save(): void { $validated = $this->validate(); if ($this->event) { // Update existing event $this->event->update($validated); session()->flash('status', __('Event erfolgreich aktualisiert!')); } else { // Create new event $this->course->courseEvents()->create([ ...$validated, 'created_by' => auth()->id(), ]); session()->flash('status', __('Event erfolgreich erstellt!')); } $this->redirect(route('courses.landingpage', ['course' => $this->course, 'country' => $this->country]), navigate: true); } public function delete(): void { if ($this->event) { $this->event->delete(); session()->flash('status', __('Event erfolgreich gelöscht!')); $this->redirect(route('courses.landingpage', ['course' => $this->course, 'country' => $this->country]), navigate: true); } } public function with(): array { return [ 'venues' => Venue::query()->orderBy('name')->get(), ]; } }; ?>