feat(events): add event categories and filtering
This commit is contained in:
@@ -8,12 +8,17 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class PublicEventService
|
||||
{
|
||||
public function list(Tenant $tenant, string $term, int $page): LengthAwarePaginator
|
||||
public function list(Tenant $tenant, string $term, int $page, ?int $categoryId = null): LengthAwarePaginator
|
||||
{
|
||||
$query = $tenant->events()
|
||||
->whereNotNull('published_at')
|
||||
->where('published_at', '<=', now());
|
||||
|
||||
if ($categoryId !== null) {
|
||||
abort_unless($tenant->eventCategories()->whereKey($categoryId)->exists(), 404);
|
||||
$query->where('event_category_id', $categoryId);
|
||||
}
|
||||
|
||||
if ($term !== '') {
|
||||
$query->where(function ($query) use ($term): void {
|
||||
$query->where('title', 'like', '%'.$term.'%')
|
||||
|
||||
Reference in New Issue
Block a user