Пример #1
0
 /**
  * Display the specified resource.
  *
  * @param $slug
  * @return \Illuminate\Http\Response
  */
 public function show($slug)
 {
     $guild = Guild::where('slug', $slug)->firstOrFail();
     $now = Carbon::now();
     if (Input::has('month')) {
         $now->month = Input::get('month');
     }
     if (Input::has('year')) {
         $now->year = Input::get('year');
     }
     $startOfMonth = $now->copy()->startOfMonth();
     $endOfMonth = $now->copy()->endOfMonth();
     $occurrences = EventOccurrence::where('begin_at', '<', $endOfMonth)->where('end_at', '>', $startOfMonth)->whereHas('event', function ($query) use($guild) {
         $query->where('guild_id', $guild->id);
     })->with('event')->get();
     $events = [];
     foreach ($occurrences as $occurrence) {
         $events[$occurrence->begin_at->day][] = $occurrence;
     }
     $monthNames = [1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     $dayNames = [1 => 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
     $month = $this->makeMonth($monthNames, $now);
     $lastRaids = EventOccurrence::with(['event', 'event.guild'])->whereHas('event.guild', function ($query) use($guild) {
         $query->where('id', $guild->id);
     })->where('begin_at', '<', Carbon::now())->orderBy('begin_at', 'desc')->limit(2)->get();
     $lastRaids = $lastRaids->reverse();
     $nextRaids = EventOccurrence::with(['event', 'event.guild'])->whereHas('event.guild', function ($query) use($guild) {
         $query->where('id', $guild->id);
     })->where('begin_at', '>', Carbon::now())->orderBy('begin_at')->limit(2)->get();
     return view('guilds.show', compact('guild', 'events', 'now', 'month', 'monthNames', 'dayNames', 'lastRaids', 'nextRaids'));
 }
 /**
  * Removes activity from given event
  *
  * @param type $id
  * @param type $activityId
  */
 public function remove($id, $occId, Request $request)
 {
     $eventOccurrence = EventOccurrence::where('event_id', $id)->findOrFail($occId);
     $activity = Activity::findOrFail($request->input('activityId'));
     $eventOccurrence->activities()->detach($activity);
     $eventOccurrence->save();
     return redirect()->back();
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $event = Event::with(['group', 'eventOccurrences'])->findOrFail($id);
     $eventOccurrences = EventOccurrence::where('event_id', $id)->paginate();
     return view('event', compact('event', 'eventOccurrences'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id, $occId)
 {
     $eventti = Event::findOrFail($id);
     if (Gate::allows('manage', $eventti)) {
         $this->validate($request, ['time' => 'required|date_format:H:i', 'place' => 'required|max:128']);
         $event = EventOccurrence::where('event_id', $id)->findOrFail($occId);
         $event->time = Carbon::createFromFormat('H:i', $request->input('time'));
         $event->place = $request->input('place');
         $event->save();
         return redirect()->action('EventOccurrenceController@show', [$id, $occId]);
     } else {
         return abort(403);
     }
 }