public function seats(Trip $trip) { $booked = $trip->passengers()->count(); $total = $trip->shuttle->seats; $lastHour = $trip->isLastHour() ? 0 : $this->lastHour($trip); return $total - $booked - $lastHour; }
public function destroy($id, FlashNotifier $notifier) { $trip = Trip::findOrFail($id); if ($trip->passengers()->count() > 0) { $notifier->error('That trip already has passengers. No way we can delete it...'); return back(); } $trip->delete(); $notifier->success('Trip successfully deleted!'); return back(); }
public function destroy(Request $request, FlashNotifier $flash) { $trip = Trip::findOrFail($request->get('trip_id')); try { $this->bookingService->cancel(Auth::user(), $trip); $flash->success("Your reservation from {$trip->origin} to {$trip->destination} was canceled."); } catch (\Exception $e) { $flash->error("There was an error processing your request"); } return redirect()->back(); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); User::truncate(); User::create(['name' => 'David Matos', 'username' => 'admin', 'password' => bcrypt('admin'), 'id_document' => str_random(10), 'karma' => random_int(200, 500), 'is_admin' => true, 'email' => 'ASM_' . str_random(5) . '@gmail.com']); User::create(['name' => 'Manuel Pereira', 'username' => 'driver', 'password' => bcrypt('driver'), 'id_document' => str_random(10), 'karma' => random_int(200, 500), 'is_driver' => true, 'email' => 'MM_' . str_random(5) . '@gmail.com']); Shuttle::truncate(); Shuttle::create(['name' => 'S01', 'seats' => 42, 'key' => 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb']); Trip::create(['shuttle_id' => 1, 'driver_id' => 2, 'origin' => 'Evora', 'destination' => 'Lisboa', 'leaves_at' => \Carbon\Carbon::now()->addMinutes(mt_rand(10, 45)), 'arrives_at' => \Carbon\Carbon::now()->addMinutes(mt_rand(120, 180))]); Trip::create(['shuttle_id' => 1, 'driver_id' => 2, 'origin' => 'Alameda', 'destination' => 'Tagus', 'leaves_at' => \Carbon\Carbon::now()->addMinutes(mt_rand(60, 90)), 'arrives_at' => \Carbon\Carbon::now()->addMinutes(mt_rand(190, 280))]); Trip::create(['shuttle_id' => 1, 'driver_id' => 2, 'origin' => 'Porto', 'destination' => 'Coimbra', 'leaves_at' => \Carbon\Carbon::now()->addMinutes(mt_rand(120, 180)), 'arrives_at' => \Carbon\Carbon::now()->addMinutes(mt_rand(300, 400))]); Model::reguard(); }
public function checkin(Request $request) { $data = $this->validateRequest($request, ['id', 'attendances']); $service = new BookingService(); foreach ($data->attendances as $attendance) { if ($attendance->user && $attendance->trip && $attendance->trip == $data->id) { $user = User::find($attendance->user); $trip = Trip::find($attendance->trip); if ($user && $trip) { $service->checkin($user, $trip); } } } $service->markMissing($trip); return $this->encryptJson([]); }