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'); } }