Files
SkinbaseNova/app/Services/Featured/FeaturedArtworkSelector.php

32 lines
973 B
PHP

<?php
declare(strict_types=1);
namespace App\Services\Featured;
use App\Models\Artwork;
use Illuminate\Database\Eloquent\Builder;
final class FeaturedArtworkSelector
{
public function querySelectedArtworks(): Builder
{
return Artwork::query()
->select('artworks.*')
->join('artwork_features as af', 'af.artwork_id', '=', 'artworks.id')
->where('af.is_active', true)
->whereNull('af.deleted_at')
->where(function (Builder $query): void {
$query->whereNull('af.expires_at')
->orWhere('af.expires_at', '>', now());
})
->where('artworks.is_public', true)
->where('artworks.is_approved', true)
->whereNull('artworks.deleted_at')
->whereNotNull('artworks.published_at')
->where('artworks.published_at', '<=', now())
->distinct()
->orderByDesc('artworks.id');
}
}