/**
  * @param $token
  * @param $food_data
  * @param transpo
  * @return json response
  */
 public static function addFood($token, $food_data, $transpo)
 {
     //todo
     $response = self::resolveNewSegmentFromActivity($token, $transpo, $food_data);
     //        return $response;
     if ($response['err code'] == '403') {
         return $response;
     }
     // inline error response
     $current_iterinary = self::getUserCurrentIterinary($token);
     //        return $current_iterinary;s
     if ($current_iterinary['err'] == 'err') {
         return response()->json($current_iterinary, 403);
     }
     $day = self::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $eat = new Eat();
     $eat->place_name = $food_data['place_name'];
     $eat->lng = $food_data['lng'];
     $eat->lat = $food_data['lat'];
     $eat->tips = $food_data['review'];
     $eat->price = $food_data['price'];
     $eat->foursquare_id = !$food_data['foursquare_id'] ? null : $food_data['foursquare_id'];
     $foodcategory = FoursquareHelper::resolveFoodCategory($food_data['category']['cat_id']);
     if (isset($foodcategory['error_code'])) {
         return $foodcategory;
     }
     // returns error
     //        return response()->json($foodcategory['main_cat']);
     $eat->main_category_id = $foodcategory['main_cat'];
     $eat->sub_category_id = $foodcategory['sub_cat'];
     $pic = $food_data['category'];
     $eat->pic_url = $pic['prefix'] . 'bg_64' . $pic['suffix'];
     //        return response()->json($eat);
     $eat->save();
     $eat->activity()->save($activity);
     //        return $eat;
     self::updateIterinary($token);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($eat, 200);
     //
     //        $current_iterinary = self::getUserCurrentIterinary($token);
     //        $day = self::getDiffInDays($token, $current_iterinary->id);
     //        $activity = new Activity();
     //        $activity->start_time = Carbon::now()->toTimeString();
     //        $activity->iterinary_id = $current_iterinary->id;
     //        $activity->day = $day;
     //        $eat = new Eat();
     //        $eat->place_name = $food_data['place_name'];
     //        $eat->lng = $food_data['lng'];
     //        $eat->lat = $food_data['lat'];
     //        $eat->tips = $food_data['review'];
     //        $eat->price = $food_data['price'];
     //
     //        $foodcategory = FoursquareHelper::resolveFoodCategory($food_data['category']['cat_id']);
     //
     ////        return response()->json($foodcategory['main_cat']);
     //        $eat->main_category_id = $foodcategory['main_cat'];
     //        $eat->sub_category_id = $foodcategory['sub_cat'];
     //        $pic = $food_data['category'];
     //        $eat->pic_url = $pic['prefix'] . '64' . $pic['suffix'];
     //
     //        self::resolveSegmentFromActivity($token);
     //
     //        $eat->save();
     //        $eat->activity()->save($activity);
     //
     //
     //        $iterinary = Iterinary::findOrFail($current_iterinary->id)
     //            ->with('activities.typable')
     //            ->first();
     //        return response()->json($iterinary, 200);
     //
     //        return response()->json($request);
 }
 public function addFoodTest(Request $request)
 {
     $request = $request->all();
     return response()->json($request);
     $food_data = $request['food'];
     $token = $request['token'];
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $eat = new Eat();
     $eat->place_name = $food_data['place_name'];
     $eat->lng = $food_data['lng'];
     $eat->lat = $food_data['lat'];
     $eat->tips = $food_data['review'];
     $eat->price = $food_data['price'];
     $foodcategory = Foursquare::resolveFoodCategory($food_data['category']['cat_id']);
     //        return response()->json($foodcategory['main_cat']);
     $eat->main_category_id = $foodcategory['main_cat'];
     $eat->sub_category_id = $foodcategory['sub_cat'];
     $pic = $food_data['category'];
     $eat->pic_url = $pic['prefix'] . '64' . $pic['suffix'];
     UserSessionHandler::resolveSegmentFromActivity($token);
     $eat->save();
     $eat->activity()->save($activity);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
     //        return response()->json($eat);
     return response()->json($request);
 }