/** * Check if access is allowed given an RFID card identifier. * * @param Resource $resource * @param string $cardId * @return Response */ public function check(Resource $resource, $cardId) { $now = Date::now(); try { $card = Card::findOrFail($cardId); // @todo: refactor for single responsibility $reservation = $resource->reservations()->where('starts_at', '<=', $now)->where('ends_at', '>', $now)->where('user_id', '=', $card->user->id)->first(); $allow = $reservation ? true : false; // } catch (ModelNotFoundException $e) { $reservation = null; $allow = false; } return ['time' => $now->format('Y-m-d H:i:s'), 'reservation' => $reservation, 'allow' => $allow]; }
/** * Display the reservations associated to the specified resource. * * @param Resource $resource * @return Response */ public function resource(Request $request, Resource $resource) { $reservations = $resource->reservations()->active(); return $this->afterId($request, $reservations)->get(); }