Skip to content

CountBuilders ​

Namespace: Unusualify\Modularous\Repositories\Logic\CountBuilders

Provides cached aggregate count queries for the standard record status tabs (all, published, draft, trash) and a generic status-by-method helper. Composes MethodTransformers.

Methods ​

MethodSignatureDescription
getCountForAll(): intCounts all records (with current $countScope filters applied)
getCountForPublished(): intCounts records matching the published() scope
getCountForDraft(): intCounts records matching the draft() scope
getCountForTrash(): intCounts soft-deleted records (onlyTrashed())
getCountFor(string $method, array $args): intCounts records for any named Eloquent scope (scope{Method} must exist on the model). Throws if the scope is not found.

All methods use cacheableCount() (from CacheableTrait) for consistent cache key generation and TTL management. The active $countScope (set by getCountByStatusSlug()) is included in the cache key.

Model Interface ​

For more efficient count queries, the model may define newCountQuery() — a query builder that excludes heavy joins or eager loads present in the standard newQuery(). If absent, newQuery() is used.

Usage ​

php
// Standard status tab counts
$all       = $repo->getCountForAll();
$published = $repo->getCountForPublished();
$draft     = $repo->getCountForDraft();
$trashed   = $repo->getCountForTrash();

// Custom scope count
$active  = $repo->getCountFor('active');
$premium = $repo->getCountFor('byPlan', ['premium']);