osm/src/FillCoordsJob.php

51 lines
958 B
PHP

<?php
namespace Zoomyboy\Osm;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class FillCoordsJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(public Geolocatable $model)
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$address = $this->model->getAddressForGeolocation();
if (!$address) {
$this->model->destroyCoordinate();
return;
}
$coordinate = $address->getCoordinate();
if (!$coordinate) {
return;
}
$this->model->fillCoordinate($coordinate);
}
}