HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Jobs/JobService.php
<?php


namespace App\Komma\Jobs;


use App\Komma\Base\Service;
use App\Komma\Jobs\Models\Job;
use Carbon\Carbon;

final class JobService extends Service
{

    private $today;

    public function __construct()
    {
        $this->today = now()->endOfDay();
        $this->today = $this->today->format('Y-m-d H:i:s');
        parent::__construct();
    }

    /**
     * Base query for get job from DB
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    private function baseJobQuery()
    {
        return $this->site
            ->jobs()
            ->with('translation', 'images')
            ->whereHas('translation')
            ->where('active', 1)
            ->where('date', '<=', $this->today)
            ->orderBy('date','desc')
            ->orderBy('created_at', 'desc');
    }

    /**
     * Get all jobs
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public function getJobs()
    {
        return $this->baseJobQuery()->get();
    }

    /**
     * Get $amount of latest jobs
     *
     * @param  int  $amount
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
     */
    public function getLatestJob($amount = 3)
    {
        return $this->baseJobQuery()
            ->take($amount)
            ->get();
    }

    public function getLastJob()
    {
        return $this->baseJobQuery()
            ->first();
    }

    /**
     * Get jobs paginated per $amount on a page
     *
     * @param  int  $amountPerPage
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getJobsPaginated($amountPerPage = 24)
    {
        return $this->baseJobQuery()->paginate($amountPerPage);
    }

    /**
     * Get the next jobs after give $job
     *
     * @param  Job  $job
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
     */
    public function getNextJobs(Job $job)
    {
        return $this->baseJobQuery()
            ->where('jobs.id', '!=', $job->id)
            ->where('date', '<=', $job->date->format(Carbon::DEFAULT_TO_STRING_FORMAT))
            ->take(2)
            ->get();
    }

}