laracraft-tech/laravel-date-scopes
Laravel Date Scopes adds a wide range of ready-made date scopes to your Eloquent models via a simple trait. Query records with ofToday(), ofLastWeek(), monthToDate(), ofLastYear(), and many more—fully chainable with any builder method like sum or avg.
composer require. The build cost is small in absolute terms, but the cost of inconsistent implementations across teams is not — this is a standardization decision more than a technical one.default_range config and per-query customRange override force this into a deliberate, documented decision instead of letting three developers each pick a different answer. Every report, invoice summary, and exec dashboard downstream inherits that decision.monthToDate, quarterToDate, yearToDate) are exactly the shapes that finance, sales, and ops stakeholders ask for. If those are on the roadmap, this package shortens the estimate on the reporting epic meaningfully.column: parameter (e.g. ofLast30Days(column: 'approved_at')) supports questions like "how many refunds were approved in the last week" or "how many accounts were verified this quarter." That's a product analytics capability, not just a query helper — it decides whether you can answer funnel-timing questions without a warehouse.startFrom: lets you scope "last 12 months" from a fixed anchor date, which matters for cohort-style analysis and for reproducing a number that was reported at a point in time (audit/defensibility).sum(), avg(), groupBy(). The PM-relevant consequence: KPI cards and trend charts can be built on the same primitives rather than needing a separate metrics layer for a small-to-mid product.Adopt when:
ofLast30Days) instead of N bespoke scopes.created_at-shaped — the package's center of gravity.Look elsewhere or defer when:
timezone assumption can silently shift daily boundaries for non-UTC customers.perDay, perWeek) — you'll still hand-write those.Adoption caveat worth surfacing early: the default is exclusive. That's a defensible statistics default but a common product surprise — expect at least one "today's numbers are zero" ticket in the first week if stakeholders assume inclusive. Make the decision explicitly and put it in the config, not in tribal knowledge. Also note the century/millennium scopes follow ordinal conventions (the 20th century is 1901–2000), which will look like a bug to anyone who hasn't read the README.
For executives: A small, MIT-licensed, low-risk library that standardizes how our product answers "how much happened in the last week/month/quarter." The real value isn't the code it saves — it's that every dashboard, report, and admin screen uses one definition of a time window instead of several. That prevents the "why does the exec dashboard disagree with the ops dashboard" conversation, which costs far more than this package does. Cost: essentially zero licenses, roughly half a day of engineering plus one product decision on inclusive vs. exclusive defaults. It's a tactical accelerator, not a platform bet — easily replaced or removed later.
For engineering: A trait you add to a model that gives you ~60 named scopes across seconds through millennia, plus period-to-date helpers, with customRange, startFrom, and column: options so you're not locked into created_at. It returns a normal Builder, so it chains with sum, avg, groupBy, and your existing scopes. Tests, changelog, and current Laravel support are in place, and it's MIT so the fallback is a fork. It removes a repetitive, bug-prone class of Carbon boundary code. Mitigation for the two real risks: (1) it's a small single-maintainer package, so if reporting is business-critical, wrap it behind an internal base model or trait so the swap-out cost stays near zero; (2) the default is exclusive — set DATE_SCOPES_DEFAULT_RANGE deliberately per product surface rather than relying on the default.
The ask: approve a one-day spike to wire it into a single reporting model behind an internal trait, confirm the inclusive/exclusive decision with the stakeholder who owns the numbers, and then decide on broader rollout.
How can I help you explore Laravel packages today?