Files
shopit-back/app/Domains/Ticketing/Event/Services/PublicEventService.php
ncoronel b0702b7e15 feat(catalog): add sales_end_at field to catalog items and implement sale logic
feat(event): include catalog items in event resource and update event service
test(seeder): add FiestaTradicionArrufoSeeder for event and catalog item setup
config: set event timezone for local event dates
2026-09-18 16:37:40 -03:00

47 lines
1.6 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',
'dates' => fn ($query) => $query->whereNull('rescheduled_to_event_date_id')->whereNull('suspended_at'),
'socialMedia',
'catalogItems.attachments',
'catalogItems.inventory',
'catalogItems.itemAttributes.attribute',
'catalogItems.variants.inventory',
'catalogItems.variants.eventDate',
'catalogItems.variants.eventDates',
]);
}
}