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 createVenue(): void { $validated = $this->validate([ 'newVenueName' => ['required', 'string', 'max:255', 'unique:venues,name'], 'newVenueCityId' => ['required', 'exists:cities,id'], 'newVenueStreet' => ['required', 'string', 'max:255'], ]); $venue = Venue::create([ 'name' => $validated['newVenueName'], 'city_id' => $validated['newVenueCityId'], 'street' => $validated['newVenueStreet'], 'slug' => str($validated['newVenueName'])->slug(), 'created_by' => auth()->id(), ]); $this->venue_id = $venue->id; $this->reset(['newVenueName', 'newVenueCityId', 'newVenueStreet']); \Flux\Flux::modal('add-venue')->close(); } public function with(): array { return [ 'venues' => Venue::query()->orderBy('name')->get(), 'cities' => City::query()->orderBy('name')->get(), ]; } }; ?>