public function index() { if (Auth::guest()) { return view('pages.home'); } //Check to make sure gender and names are populated $user = Auth::user(); $fields = ['first_name' => $user->first_name, 'last_name' => $user->last_name, 'gender' => $user->gender]; $validation = Validator::make($fields, User::$baseRules); if (!$validation->passes()) { return redirect('user/name-and-gender'); } //Check to make sure user has choson categories if (!$this->categoryAccount->where('user_id', $user->id)->first()) { return redirect('user/categories'); } $chosenCategories = $this->categoryAccount->where('user_id', Auth::user()->id)->orderByRaw('RAND()')->get(); //Get one random task for the "one for the road" $oneForTheRoad = array(); foreach ($chosenCategories as $category) { $events = $this->event->where('type', $category->category_id)->orderByRaw('RAND()')->get(); foreach ($events as $event) { if (!$this->eventUser->where('event_id', $event->id)->where('user_id', Auth::user()->id)->first() && !$this->eventUser->where('user_id', Auth::user()->id)->where('created_at', '<=', date('Y-m-d 24:00:00'))->where('created_at', '>=', date('Y-m-d 00:00:00'))->where('complete', 1)->first()) { array_push($oneForTheRoad, ['id' => $event->id, 'name' => $event->name, 'description' => $event->description, 'class' => 'active']); } else { array_push($oneForTheRoad, ['id' => '0', 'name' => 'None for today!', 'description' => 'One for the road has completed', 'class' => 'inactive']); } } } $category = $this->category; return view('pages.dashboard', compact('category', 'chosenCategories', 'oneForTheRoad')); }
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')]); }
protected function getParticipantsOf() { $data = EventUser::where('event_user.event_id', $this->request->event_id)->join('users', 'event_user.user_id', '=', 'users.id'); $data = applyParams($data, $this->request)->get(); return data(compact('data')); }
/** * Delete the join relation between an user and an event. * * @return Response */ public function notGoingEvent($event_id) { $user_id = \Auth::id(); $eventUser = EventUser::where('user_id', $user_id)->where('event_id', $event_id)->first(); if ($eventUser) { $eventUser->delete(); } return redirect()->route('events.show', $event_id); }