/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $this->validate($request, ['end_date' => 'date', 'start_date' => 'date', 'when' => 'in:past,future']); $queryParameters = array_filter($request->only(['end_date', 'start_date', 'when'])); $events = Event::query(); if (array_key_exists('end_date', $queryParameters)) { $events->where('end_date', $queryParameters['end_date']); } if (array_key_exists('start_date', $queryParameters)) { $events->where('start_date', $queryParameters['start_date']); } if (array_key_exists('when', $queryParameters)) { $now = Carbon::now(); switch ($queryParameters['when']) { case 'past': $events->where('end_date', '<', $now->toIso8601String()); break; case 'future': $events->where('start_date', '>', $now->toIso8601String()); break; default: abort(500); } } return response()->json($events->paginate()); }
public function relatedEvents() { $query = Event::query(); $this->relatedEventsAccount($query); $this->relatedEventsEnvelope($query); $this->relatedEventsRevenue($query); $this->relatedEventsTransfer($query); $this->relatedEventsIncome($query); $this->relatedEventsOutcome($query); return $query->orderBy('id', 'desc'); }