feat(events): expose published events to storefront

This commit is contained in:
2026-09-18 14:33:28 -03:00
parent 8d2250d247
commit f6e8716218
5 changed files with 110 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?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');
}
}