first(); if ($user){ $lastLocation = $user->lastCoordinates; if ($lastLocation){ $minLat = $message['location']['latitude'] - 0.0005; $maxLat = $message['location']['latitude'] + 0.0005; $minLng = $message['location']['longitude'] - 0.0008; $maxLng = $message['location']['longitude'] + 0.0008; $newLat = false; $newLng = false; if ($lastLocation->lat < $minLat || $lastLocation->lat > $maxLat){ $newLat = $message['location']['latitude']; } if ($lastLocation->lng < $minLng || $lastLocation->lng > $maxLng){ $newLng = $message['location']['longitude']; } if($newLat || $newLng){ $newLocation = new Location(); $newLocation->lat = $newLat ?: $lastLocation->lat; $newLocation->lng = $newLng ?: $lastLocation->lng; $newLocation->user_id = $user->id; $newLocation->save(); Log::info('я сохранил новую координату'); } } else { $newLocation = new Location(); $newLocation->lat = $message['location']['latitude']; $newLocation->lng = $message['location']['longitude']; $newLocation->user_id = $user->id; $newLocation->save(); } } } } }