public function addStop(Request $request)
 {
     $stop_data = $request->input('stop');
     $transpo_data = $request->input('transpo');
     $token = $request->input('token');
     $stop = new Stop();
     $stop->place_name = $stop_data['place_name'];
     $stop->details = $stop_data['stop_details'];
     $stop->price = $stop_data['price'];
     $stop->lat = $stop_data['lat'];
     $stop->lng = $stop_data['lng'];
     UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo_data, $stop);
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     //        return $current_iterinary;s
     if ($current_iterinary['err'] == 'err') {
         return response()->json($current_iterinary, 403);
     }
     $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;
     $stop->save();
     $stop->activity()->save($activity);
     return response()->json($stop);
 }
 public function addHotelTest(Request $request)
 {
     $request = $request->all();
     $food_data = $request['hotel'];
     $token = $request['token'];
     $transpo = $request['transpo'];
     $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $food_data);
     //        return response()->json($response);
     $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;
     $hotel = new Hotel();
     $hotel->hotel_name = $food_data['place_name'];
     $hotel->lng = $food_data['lng'];
     $hotel->lat = $food_data['lat'];
     $hotel->tips = $food_data['review'];
     $hotel->price = $food_data['price'];
     $hotel->pic_url = '';
     //        return response()->json($eat);
     $hotel->save();
     $hotel->activity()->save($activity);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
 }
 public static function addOtherActivity($token, $other_data, $transpo)
 {
     $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $other_data);
     //        return response()->json($response);
     $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;
     $other_activity = new OtherActivity();
     $other_activity->name = $other_data['place_name'];
     $other_activity->lng = $other_data['lng'];
     $other_activity->lat = $other_data['lat'];
     $other_activity->review = $other_data['review'];
     $other_activity->expense = $other_data['expense'];
     //        return response()->json($eat);
     $other_activity->save();
     $other_activity->activity()->save($activity);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
 }
 public function addPhotoToIterinary()
 {
     $data = Input::get('image');
     $token = Input::get('token');
     //get the base-64 from data
     $iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $photo = new IterinaryPhoto();
     //decode base64 string
     //        $image =  base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
     $img = str_replace('data:image/png;base64,', '', $data);
     $img = str_replace(' ', '+', $img);
     $data = base64_decode($img);
     $png_url = str_random(16) . ".png";
     $photo->image_path = 'http://localhost:8000/api/img/' . $png_url;
     $path = public_path('images/' . $png_url);
     $result = file_put_contents($path, $data);
     $iterinary->photos()->save($photo);
     // $result = file_put_contents($path, $image);
     $response = array('status' => 'success', 'data' => $result);
     return response()->json($response);
 }