File: /var/www/limestate-admin/app/Models/Export/ExportData.php
<?php
namespace App\Models\Export;
use App\Models\ExternalServiceRelation;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $flat_id
* @property string $service
* @property string $created_at
*/
class ExportData extends Model
{
protected $table = 'export_data';
const UPDATED_AT = null;
protected $fillable = [
'flat_id',
'service',
];
public static function clear(string $service): void
{
self::query()->where('service', $service)->delete();
}
public static function getUsedIds(string $service): array
{
return self::query()->where('service', $service)->pluck('flat_id')->toArray();
}
private static function addOfferId(int $offerId, string $service): void
{
$data = ['flat_id' => $offerId, 'service' => $service];
self::query()->firstOrCreate($data, $data);
}
public static function addYandexOfferId(int $offerId): void
{
self::addOfferId($offerId, ExternalServiceRelation::SERVICE_YANDEX);
}
public static function addCianOfferId(int $offerId): void
{
self::addOfferId($offerId, ExternalServiceRelation::SERVICE_CIAN);
}
public static function addAvitoOfferId(int $offerId): void
{
self::addOfferId($offerId, ExternalServiceRelation::SERVICE_AVITO);
}
}