feat(events): expose published events to storefront
This commit is contained in:
36
app/Domains/Ticketing/Event/Services/PublicEventService.php
Normal file
36
app/Domains/Ticketing/Event/Services/PublicEventService.php
Normal 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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user