/** * Run the database seeds. * * @return void */ public function run() { // --------------------------------------------------------------------- // CONFERENCE 2 // --------------------------------------------------------------------- $conference = Conference::find(2); $vehicle = ['name' => 'Airport Taxi', 'passenger_count' => 0, 'capacity' => 7, 'type' => 'arrival']; $vehicle = new ConferenceVehicle($vehicle); $vehicle->conference()->associate($conference); $vehicle->save(); $vehicle = ['name' => 'Airport Taxi', 'passenger_count' => 0, 'capacity' => 7, 'type' => 'departure']; $vehicle = new ConferenceVehicle($vehicle); $vehicle->conference()->associate($conference); $vehicle->save(); $event = $conference->events()->first(); $vehicle = ['name' => 'Hotel Shuttle', 'passenger_count' => 0, 'capacity' => 50, 'type' => 'arrival']; $vehicle = new EventVehicle($vehicle); $vehicle->event()->associate($event); $vehicle->save(); $vehicle = ['name' => 'Hotel Shuttle', 'passenger_count' => 0, 'capacity' => 50, 'type' => 'departure']; $vehicle = new EventVehicle($vehicle); $vehicle->event()->associate($event); $vehicle->save(); }
/** * Delete a Vehicle of an Event. * * @param VehicleRequest $request * @param int $eid * @param int $vid * @return Response */ public function destroy(VehicleRequest $request, $eid, $vid) { try { $user = $this->isEventManager($request, $eid); if (!$user) { return response()->error(403, 'You are not a manager of this event!'); } $event = Event::find($eid); if (!$event) { return response()->error(404, 'Event Not Found'); } $vehicle = EventVehicle::find($vid); if (!$vehicle) { return response()->error(404, 'Vehicle Not Found'); } $vehicle->delete(); return response()->success(); } catch (Exception $e) { return response()->error(); } }
/** * Delete a Passenger of an Event Vehicle. * * @param Request $request * @param int $eid * @param int $vid * @param int $pid * @return Response */ public function destroy(Request $request, $eid, $vid, $pid) { try { $event = Event::find($eid); if (!$event) { return response()->error(404, 'Event Not Found'); } $vehicle = EventVehicle::find($vid); if (!$vehicle) { return response()->error(404, 'Vehicle Not Found'); } $profile = Profile::find($pid); if (!$profile) { return response()->error(404, 'Profile Not Found'); } $vehicle->passengers()->detach($profile); $vehicle->decrement('passenger_count'); return response()->success(); } catch (Exception $e) { return response()->error($e); } }