Download the PHP package laracraft-tech/laravel-date-scopes without Composer
On this page you can find all versions of the php package laracraft-tech/laravel-date-scopes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laracraft-tech/laravel-date-scopes
More information about laracraft-tech/laravel-date-scopes
Files in laracraft-tech/laravel-date-scopes
Package laravel-date-scopes
Short Description Some useful date scopes for your Laravel Eloquent models!
License MIT
Homepage https://github.com/laracraft-tech/laravel-date-scopes
Informations about the package laravel-date-scopes
Laravel Date Scopes
This package provides a big range of useful date scopes for your Laravel Eloquent models!
Let's assume you have a Transaction
model.
If you now give it the DateScopes
trait, you can do something like this:
ToC
Installation
Configuration
Global configuration
Fluent date range configuration
Fluent created_at column configuration
Custom start date
Scopes
Installation
You can install the package via composer:
Configuration
Inclusive/Exclusive
In statistics, when asking for "the last 7 days", the current day may or may not be included in the calculation depending on the context and the specific requirements of the analysis.
If you want to include the current day in the calculation, you would generally use an inclusive range, meaning that you would include records created on the current day as well as records created in the previous 6 days.
If you want to exclude the current day in the calculation, you would generally use an exclusive range, meaning that you would include records created in the previous 7 days, but not records created on the current day.
Ultimately, it depends on the context and what you're trying to achieve with your data. It's always a good idea to clarify the requirements and expectations with stakeholders to ensure that you're including or excluding the correct records.
The same concept applies to other time intervals like weeks, months, quarters, and years etc.
The default for this package is exclusive approach, which means when you for instance query for the last 7 days it will not include the current day! You can change the default if you need in the published config file.
Global configuration
You can publish the config file with:
This is the contents of the published config file:
If you want to change the default range to inclusive set DATE_SCOPES_DEFAULT_RANGE=inclusive
in your .env
.
Fluent date range configuration
As already mentioned above in the default_range
config description text,
you can also fluently specify the range for quite every scope we offer
directly when using the scope:
This will do an inclusive query (today-6 days), even though the global default range here was set to exclusive.
Fluent created_at column configuration
If you only want to change the field in one of your models and not globally just do:
Custom start date
If you want data not starting from now, but from another date, you can do this with:
Scopes
seconds
minutes
hours
days
weeks
months
quarters
years
decades
centuries
millenniums
toNow/toDate
Seconds
Minutes
Hours
Days
Weeks
Months
Quarters
Years
Decades
Centuries
The centuries may return a different range then you maybe would expect. For instance Transaction::ofLastCentury()
would apply a range from 1901-01-01 00:00:00 to 2000-12-31 23:59:59.
Maybe you would expect a range from: 1900-01-01 00:00:00 to 1999-12-31 23:59:59.
Checkout Wikipedia for this behavior: https://en.wikipedia.org/wiki/20th_century
Millenniums
The millenniums may return a different range then you maybe would expect. For instance Transaction::ofLastMillennium()
would apply a range from 1001-01-01 00:00:00 to 2000-12-31 23:59:59.
Maybe you would expect a range from: 1000-01-01 00:00:00 to 1999-12-31 23:59:59.
Checkout Wikipedia for this behavior: https://en.wikipedia.org/wiki/2nd_millennium
toNow/toDate
Testing
Upgrading
Please see UPGRADING for details.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
Please review our security policy on how to report security vulnerabilities.
Credits
- Zacharias Creutznacher
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-date-scopes with dependencies
illuminate/contracts Version ^9.0 || ^10.0 || ^11.0
illuminate/database Version ^9.0 || ^10.0 || ^11.0
illuminate/support Version ^9.0 || ^10.0 || ^11.0
nesbot/carbon Version ^2.66 || ^3.6
spatie/laravel-package-tools Version ^1.13.0