public function removeTrip() { if (isset($_POST['itineraryKey']) && isset($_POST['tripId']) && isset($_POST['userKey'])) { $itineraryKey = $_POST['itineraryKey']; $tripId = $_POST['tripId']; $userKey = $_POST['userKey']; } else { $baseURL = '../public/'; return \View::make('trips')->with('baseURL', $baseURL); } $tripItinerary = Trip::getTrip($itineraryKey); if (empty($tripItinerary)) { $baseURL = '../public/'; return \View::make('trips')->with('baseURL', $baseURL); } /* Check the key */ if ($userKey == '') { $errorMessage = 'Key Required'; } else { if (Hash::check($userKey, $itineraryKey)) { $errorMessage = ''; } else { $errorMessage = 'Invalid Key'; } } if ($errorMessage == '') { Trip::deleteTrip($tripId); } $allTrips = Trip::getAllTrips(); $trips = null; for ($i = 0; $i < sizeof($allTrips); $i++) { $tripObject = json_decode($allTrips[$i]->trip_object); if (isset($tripObject[$i]->places)) { $tripPotstops = sizeof($tripObject[$i]->places); } else { $tripPotstops = null; } $trips[$i] = ['from' => $tripObject[0]->city, 'from_formatted_address' => $tripObject[0]->formatted_address, 'from_lat' => $tripObject[0]->lat, 'from_lng' => $tripObject[0]->lng, 'to' => $tripObject[sizeof($tripObject) - 1]->city, 'to_formatted_address' => $tripObject[sizeof($tripObject) - 1]->formatted_address, 'to_lat' => $tripObject[sizeof($tripObject) - 1]->lat, 'to_lng' => $tripObject[sizeof($tripObject) - 1]->lng, 'id' => $allTrips[$i]->trip_id, 'key' => $allTrips[$i]->trip_key, 'pitstops' => $tripPotstops]; } $trips = str_replace("'", "", json_encode($trips)); $baseURL = '../public/'; if ($errorMessage != '') { return \View::make('trips')->with('trips', $trips)->with('errorMessage', $errorMessage)->with('baseURL', $baseURL); } else { return \View::make('trips')->with('trips', $trips)->with('errorMessage', $errorMessage)->with('baseURL', $baseURL); } }