File: //var/www/quadcode-jobs/app/Models/Location.php
<?php
namespace App\Models;
use App\Helpers\CollectionHelper;
use App\Repositories\OfficeRepository;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* @property int $id
* @property string $deleted_at
* @property string $created_at
* @property string $updated_at
* @property int $position
* @property int $id_external
* @property string $map_coords
* @property int $count_positions
* @property string $slug
* @property string $title
* @property string $description
* @property string $title_prepositional
* @property string $country
* @property bool $active
*
* @property Vacancy[] $vacancies
*/
class Location extends Model
{
protected $fillable = [
'position',
'id_external',
'map_coords',
'count_positions',
'slug',
'title',
'description',
'title_prepositional',
'country',
'about_office',
'active',
];
public function isLarnaca(): bool
{
return OfficeRepository::LARNACA === $this->title;
}
public function vacancies(): BelongsToMany
{
return $this->belongsToMany(Vacancy::class);
}
public function getVacanciesList(): LengthAwarePaginator
{
$title = OfficeRepository::LIMASSOL === $this->title ? OfficeRepository::CYPRUS : $this->title;
/** @var LeverLocation $location */
$location = LeverLocation::query()->where('title', $title)->first();
$vacancies = empty($location) ? new Collection([]) : $location->vacancies;
return CollectionHelper::paginate($vacancies, 10);
}
}