File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Vacancies/VacancyService.php
<?php
namespace App\Komma\Vacancies;
use App\Komma\Base\Service;
use App\Komma\Vacancies\Models\Vacancy;
final class VacancyService extends Service
{
/**
* Base query for get vacancy from DB
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
private function baseVacancyQuery()
{
return Vacancy::where('active', 1)
->with('translation')
->whereHas('translation', function ($q) {
$q->whereNotNull('name')
->where('name', '!=', '');
})
->orderBy('lft');
}
/**
* Get all vacancies
*
* @param int $amountPerPage
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getVacanciesPaginated(int $amountPerPage = 6)
{
return $this->baseVacancyQuery()->paginate($amountPerPage);
}
/**
* Get all vacancies
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getVacancies()
{
return $this->baseVacancyQuery()->get();
}
/**
* Get other vacancies except this proved one
*
* @param int $currentVacancyId
* @param int $amount
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
*/
public function getOtherVacancies(int $currentVacancyId, int $amount = 3)
{
return $this->baseVacancyQuery()
->where('id', '!=', $currentVacancyId)
->take($amount)
->get();
}
}