Beispiel #1
0
 public static function boot()
 {
     parent::boot();
     Gps::creating(function ($gps) {
         $gps->company_id = $gps->company_id ?: Auth::user()['company_id'];
     });
 }
 public function testUpdateGpsData()
 {
     $this->get('/vehicle/fleet/dashboard/1990-01-01/1')->seeJsonContains(["latitude" => "80.0000000", "longitude" => "10.0000000"]);
     $updateDatetime = new \DateTime(date("Y-m-d H:i:s"));
     $updateDatetime->modify("-1 second");
     $updateDatetime = $updateDatetime->format("Y-m-d H:i:s");
     Gps::forceCreate(['company_id' => 1, 'vehicle_id' => 1, 'driver_id' => 3, 'latitude' => '50', 'longitude' => '20']);
     $this->get('/vehicle/fleet/dashboard/' . $updateDatetime . '/1')->seeJsonContains(["latitude" => "50.0000000", "longitude" => "20.0000000"]);
 }
 private function getFleetGpsData($updateDatetime = null, $vehicleId = null)
 {
     $gpsQuery = Gps::where('company_id', Auth::user()['company_id']);
     if (!empty($updateDatetime)) {
         $gpsQuery = $gpsQuery->where('created_at', '>', $updateDatetime);
     }
     if (!empty($vehicleId)) {
         $gpsQuery = $gpsQuery->where('vehicle_id', $vehicleId);
     }
     $gpsQuery = $gpsQuery->orderBy('created_at', 'asc')->get();
     $gpsData = [];
     if (!empty($gpsQuery)) {
         foreach ($gpsQuery as $gps) {
             $objGps = new \stdClass();
             $objGps->latitude = HelperRepository::manageEmptyValue($gps->latitude);
             $objGps->longitude = HelperRepository::manageEmptyValue($gps->longitude);
             $gpsData[$gps->vehicle_id] = $objGps;
         }
     }
     return $gpsData;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('gps')->delete();
     Gps::forceCreate(['company_id' => 1, 'vehicle_id' => 1, 'driver_id' => 3, 'latitude' => '80', 'longitude' => '10']);
 }
 public function getDriverProfile($idContact)
 {
     $results = Gps::select('speed')->where('driver_id', $idContact)->whereNotNull('speed')->orderBy('id', 'desc')->take(50)->get();
     return $results;
 }
 public function getLocalizationData($idVehicle)
 {
     $localizationData = Gps::where('vehicle_id', $idVehicle)->orderBy('id', 'desc')->first();
     return $localizationData;
 }