osm/src/FillCoordsJob.php

54 lines
1015 B
PHP
Raw Normal View History

2023-05-16 14:29:51 +02:00
<?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;
public Geolocatable $model;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Geolocatable $model)
{
$this->model = $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);
}
}