/** * Returns either all unavailables for the passed in advisor_id * OR will return only unavailables for the passed in advisor_id and filter_date * * @param int $advisor_id, string filter_date * @return Response * * api/v1/advisors/2/available/* * api/v1/advisors/2/available/2014-11-17 */ public function show($advisor_id, $filter_date) { $unavailables = null; $advisor = User::find($advisor_id); // Make sure advisor exists if ($advisor == null) { return Response::json(array('message' => 'Adviser does not exist'), 400); } if ($filter_date == "*") { // Return all availables for the passed in advisor id $unavailables = $advisor->unavailables; } else { // Return only availables that fall on the passed in // filter date // Make sure the passed in date is valid try { $dt = Carbon::now(); $dt->createFromFormat('Y-m-d', $filter_date); } catch (InvalidArgumentException $e) { return Response::json(array('message' => 'Invalid date'), 400); } $min = $filter_date . " 00:00:00"; $max = $filter_date . " 23:59:59"; $unavailables = Unavailable::where('user_id', '=', $advisor_id)->whereBetween('start', array($min, $max))->get(); } return $unavailables; }