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/stielman.komma.nl/app/Events/EventService.php
<?php


namespace App\Events;


use App\Base\Service;
use App\Events\Models\Event;
use Carbon\Carbon;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Query\Builder;

final class EventService 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 event from DB
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    private function baseEventQuery()
    {
        return Event::with('translation', 'images')
            ->where('active', 1)
            ->where('date', '>=', $this->today)
            ->orderBy('date','asc')
            ->orderBy('created_at', 'asc')
            ->whereHas('translation');
    }

    /**
     * get all events
     *
     * @return \Illuminate\Database\Eloquent\Builder[]|Collection
     */
    public function getAllEvents()
    {
        return $this->baseEventQuery()->get();
    }

    /**
     * Get the next events after give $event
     *
     * @param  Event  $event
     * @return Collection|\Illuminate\Support\Collection
     */
    public function getNextEvents(Event $event)
    {
        return $this->baseEventQuery()
            ->where('events.id', '!=', $event->id)
            ->where('date', '>=', $this->today)
            ->take(4)
            ->get();
    }

}