Files
shopit-back/app/Domains/Ticketing/Event/Services/PublicEventService.php

37 lines
1.2 KiB
PHP

<?php
namespace App\Domains\Ticketing\Event\Services;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Models\Event;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
class PublicEventService
{
public function list(Tenant $tenant, string $term, int $page): LengthAwarePaginator
{
$query = $tenant->events()
->whereNotNull('published_at')
->where('published_at', '<=', now());
if ($term !== '') {
$query->where(function ($query) use ($term): void {
$query->where('title', 'like', '%'.$term.'%')
->orWhere('subtitle', 'like', '%'.$term.'%')
->orWhere('location', 'like', '%'.$term.'%');
});
}
return $query->with('attachment')->orderByDesc('published_at')->orderByDesc('id')->paginate(15, ['*'], 'page', $page);
}
public function find(Tenant $tenant, Event $event): Event
{
abort_unless($event->tenant_code === $tenant->codigo
&& $event->published_at !== null
&& $event->published_at->isPast(), 404);
return $event->load('attachment');
}
}