コード例 #1
0
 public function key($id, EditShuttleKeyRequest $request, FlashNotifier $flash)
 {
     $shuttle = Shuttle::findOrFail($id);
     $shuttle->key = $request->get('key');
     $flash->success('Shuttle key successfully modified!');
     return back();
 }
コード例 #2
0
 /**
  * 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();
 }
コード例 #3
0
 public function store(CreateTripRequest $request, FlashNotifier $flash)
 {
     if (!Shuttle::find($request->shuttle_id)) {
         $flash->error("Error creating trip. Shuttle {$request->id} does not exist.");
         return redirect()->back()->withInput();
     }
     $driver = User::find($request->driver_id);
     if ($driver == null) {
         $flash->error("Error creating trip. User {$request->driver_id} does not exist.");
         return redirect()->back()->withInput();
     }
     if (!$driver->isDriver()) {
         $flash->error("Error creating trip. User {$driver->name} is not a driver.");
         return redirect()->back()->withInput();
     }
     $leaves = new Carbon($request->leaves_at);
     $arrives = new Carbon($request->arrives_at);
     Trip::create(['shuttle_id' => $request->shuttle_id, 'driver_id' => $request->driver_id, 'origin' => $request->origin, 'destination' => $request->destination, 'leaves_at' => $leaves, 'arrives_at' => $arrives]);
     $flash->success('Trip successfully created!');
     return back();
 }
コード例 #4
0
 /**
  * @param $name
  * @return mixed
  * @throws BadRequestDataException
  */
 protected function findShuttle($name)
 {
     $shuttle = Shuttle::where('name', $name)->first();
     if (!$shuttle) {
         throw new BadRequestDataException("Shuttle {$name} does not exist");
     }
     $this->shuttle = $shuttle;
     return $shuttle;
 }