country = request()->route('country'); $this->name = auth()->user()->name ?? ''; $this->loadAttendees(); } public function with(): array { return [ 'event' => $this->event->load('meetup'), ]; } private function getUserIdentifier(): string { return auth()->check() ? 'id_'.auth()->id() : 'anon_'.session()->getId(); } private function loadAttendees(): void { $identifier = $this->getUserIdentifier(); $attendees = collect($this->event->attendees ?? []); $mightAttendees = collect($this->event->might_attendees ?? []); // Check if user is in attendees $attendeeEntry = $attendees->first(fn($v) => str($v)->startsWith($identifier)); if ($attendeeEntry) { $this->name = str($attendeeEntry)->after('|')->toString(); $this->willShowUp = true; } // Check if user is in might_attendees $mightAttendeeEntry = $mightAttendees->first(fn($v) => str($v)->startsWith($identifier)); if ($mightAttendeeEntry) { $this->name = str($mightAttendeeEntry)->after('|')->toString(); $this->perhapsShowUp = true; } $this->attendees = $this->mapAttendees($attendees); $this->mightAttendees = $this->mapAttendees($mightAttendees); } private function mapAttendees($collection): array { return $collection->map(function ($value) { $isAnon = str($value)->contains('anon_'); $id = $isAnon ? -1 : str($value)->before('|')->after('id_')->toInteger(); return [ 'id' => $id, 'user' => $id > 0 ? User::query() ->select(['id', 'name', 'profile_photo_path']) ->find($id) ?->append('profile_photo_url') ->toArray() : null, 'name' => str($value)->after('|')->toString(), ]; })->toArray(); } public function attend(): void { $this->validate(); $this->removeFromLists(); $attendees = collect($this->event->attendees ?? []); $entry = $this->getUserIdentifier().'|'.$this->name; if (!$attendees->contains($entry)) { $attendees->push($entry); $this->event->update(['attendees' => $attendees->toArray()]); } $this->loadAttendees(); } public function mightAttend(): void { $this->validate(); $this->removeFromLists(); $mightAttendees = collect($this->event->might_attendees ?? []); $entry = $this->getUserIdentifier().'|'.$this->name; if (!$mightAttendees->contains($entry)) { $mightAttendees->push($entry); $this->event->update(['might_attendees' => $mightAttendees->toArray()]); } $this->loadAttendees(); } public function cannotCome(): void { $this->removeFromLists(); $this->loadAttendees(); } private function removeFromLists(): void { $identifier = $this->getUserIdentifier(); $attendees = collect($this->event->attendees ?? []) ->reject(fn($v) => str($v)->startsWith($identifier)); $mightAttendees = collect($this->event->might_attendees ?? []) ->reject(fn($v) => str($v)->startsWith($identifier)); $this->event->update([ 'attendees' => $attendees->toArray(), 'might_attendees' => $mightAttendees->toArray(), ]); $this->willShowUp = false; $this->perhapsShowUp = false; } }; ?>
{{ $event->meetup->name }} / {{ $event->start->format('d.m.Y') }}
{{ $event->start->format('d.m.Y') }}
{{ $event->start->format('H:i') }} Uhr
{{ $event->start->isoFormat('dddd, D. MMMM YYYY') }}
@if($event->location)
{{ __('Ort') }}
{{ $event->location }}
@endif @if($event->description)
{{ __('Beschreibung') }} {{ $event->description }}
@endif @if($event->link)
{{ __('Mehr Informationen') }}
@endif
{{ __('Teilnahme') }}
@if(!auth()->check()) {{ __('Du bist nicht eingloggt und musst deshalb den Namen selbst eintippen.') }} {{ __('Log in') }} @endif {{ __('Dein Name') }} @error('name') {{ $message }} @enderror
{{ __('Ich komme') }} {{ __('Vielleicht') }} @if($willShowUp || $perhapsShowUp) {{ __('Absagen') }} @endif
@if(count($attendees) > 0)
{{ __('Zusagen') }} ({{ count($attendees) }})
@foreach($attendees as $attendee) @if($attendee['user'])
{{ $attendee['name'] }}
@else {{ $attendee['name'] }} @endif @endforeach
@endif @if(count($mightAttendees) > 0)
{{ __('Vielleicht') }} ({{ count($mightAttendees) }})
@foreach($mightAttendees as $attendee) @if($attendee['user'])
{{ $attendee['name'] }}
@else {{ $attendee['name'] }} @endif @endforeach
@endif
{{ __('Zurück zum Meetup') }}