Example #1
0
 protected function toggleParticipant(Event $event)
 {
     $isParticipant = !empty(EventUser::where('user_id', $this->request->participant_id)->where('event_id', $event->id)->first());
     if ($isParticipant) {
         $event->users()->detach([$this->request->participant_id]);
         $value = -1;
     } else {
         $event->users()->attach([$this->request->participant_id]);
         $value = 1;
     }
     return data([compact('value')]);
 }