Ejemplo n.º 1
0
 /**
  * Get last_tracked attribute
  *
  * @return obj
  */
 public function getLastTrackedAttribute()
 {
     $firstObj = VehicleLocation::where('vehicle_id', $this->id)->orderBy('timestamp', 'desc');
     try {
         $firstObj->first();
         //Do stuff when user exists.
     } catch (ErrorException $e) {
         //Do stuff if it doesn't exist.
         return array();
     }
 }
Ejemplo n.º 2
0
 public function updateVehiclePosition(Request $request)
 {
     $all = $request->all();
     $Vehicle = Vehicle::where('user_id', '=', JWTAuth::parseToken()->toUser()->id)->first();
     $lastTracked = VehicleLocation::where('vehicle_id', $Vehicle->id)->orderBy('timestamp', 'desc')->first();
     if (abs($lastTracked->lat - $all['position']["latitude"]) == 0 && abs($lastTracked->lon - $all['position']["longitude"]) == 0) {
         $lastTracked->updated_at = date('Y-m-d H:i:s', time());
         $lastTracked->timestamp = time();
         $lastTracked->save();
     } else {
     }
     $vehicleLocation = new \App\VehicleLocation(array('lat' => $all['position']["latitude"], 'lon' => $all['position']['longitude'], 'vehicle_id' => $Vehicle->id, 'timestamp' => time(), 'connection_type' => 'spotter_app'));
     $vehicleLocation->save();
     $Vehicle->updated_at = date('Y-m-d H:i:s', time());
     $Vehicle->save();
     //echo $vehicleLocation->id;
     //$result['vessels'] = $vehicles->toArray();
     //return $result;
     return $Vehicle;
 }