### Package Installation Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Provides the Composer command to install the laravel-date-scopes package into a Laravel project. ```bash composer require laracraft-tech/laravel-date-scopes ``` -------------------------------- ### Configuration File Example Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Displays the default contents of the published configuration file for laravel-date-scopes, including options for default date range and the created_at column name. ```php return [ /** * If you want to include the current day/week/month/year etc. in the range, * you could use the inclusive range here as a default. * Note that you can also fluently specify the range for quite every scope we offer * directly when using the scope: * Transaction::ofLast7Days(customRange: DateRange::INCLUSIVE); (this works for all but the singular "ofLast"-scopes) * This will do an inclusive query, even though the global default range here is set to exclusive. */ 'default_range' => env('DATE_SCOPES_DEFAULT_RANGE', DateRange::EXCLUSIVE->value), /** * If you use a global custom created_at column name, change it here. */ 'created_column' => env('DATE_SCOPES_CREATED_COLUMN', 'created_at'), ]; ``` -------------------------------- ### Hours Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Shows examples of querying transactions by hours using scopes, including predefined intervals and custom hour counts. ```php // query by HOURS Transaction::ofLastHour(); // query transactions created during the last hour Transaction::ofLast6Hours(); // query transactions created during the last 6 hours Transaction::ofLast12Hours(); // query transactions created during the last 12 hours Transaction::ofLast18Hours(); // query transactions created during the last 18 hours Transaction::ofLast24Hours(); // query transactions created during the last 24 hours Transaction::ofLastHours(48); // query transactions created during the last N hours ``` -------------------------------- ### Custom Start Date for Queries Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Illustrates how to specify a custom start date for date range queries, allowing filtering from a specific point in time. ```php // query transactions created during 2019-2020 Transaction::ofLastYear(startFrom: '2020-01-01') ``` -------------------------------- ### Seconds Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Provides examples of using scopes to query transactions based on seconds, including specific intervals and custom counts. ```php // query by SECONDS Transaction::ofJustNow(); // query transactions created just now Transaction::ofLastSecond(); // query transactions created during the last second Transaction::ofLast15Seconds(); // query transactions created during the last 15 seconds Transaction::ofLast30Seconds(); // query transactions created during the last 30 seconds Transaction::ofLast45Seconds(); // query transactions created during the last 45 seconds Transaction::ofLast60Seconds(); // query transactions created during the last 60 seconds Transaction::ofLastSeconds(120); // query transactions created during the last N seconds ``` -------------------------------- ### Days Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Provides examples of using scopes to query transactions by days, including today, yesterday, specific intervals, and custom day counts. ```php // query by DAYS Transaction::ofToday(); // query transactions created today Transaction::ofYesterday(); // query transactions created yesterday Transaction::ofLast7Days(); // query transactions created during the last 7 days Transaction::ofLast21Days(); // query transactions created during the last 21 days Transaction::ofLast30Days(); // query transactions created during the last 30 days Transaction::ofLastDays(60); // query transactions created during the last N days ``` -------------------------------- ### Customizing Date Range Inclusivity Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Illustrates how to override the default date range inclusivity (exclusive) for specific queries. This example shows how to include the current day when querying for the last 7 days. ```php use LaracraftTech\LaravelDateScopes\Enums\DateRange; // This will do an inclusive query for the last 7 days Transaction::ofLast7Days(customRange: DateRange::INCLUSIVE); ``` -------------------------------- ### PHP: Using Named Arguments for startFrom Parameter Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/UPGRADING.md Demonstrates the change required when upgrading from v1 to v2 of Laravel Date Scopes. The `startFrom` parameter was added, necessitating the use of named arguments for clarity and compatibility. ```php Transaction::ofLast7Days(customRange: DateRange::INCLUSIVE); ``` -------------------------------- ### Publishing Configuration Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Shows the Artisan command to publish the package's configuration file, allowing for customization of default settings. ```bash php artisan vendor:publish --tag="date-scopes-config" ``` -------------------------------- ### Run Tests Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Execute the project's test suite using Composer. ```bash composer test ``` -------------------------------- ### Setting Default Range via .env Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Explains how to change the default date range behavior of the package to inclusive by setting an environment variable in the `.env` file. ```bash DATE_SCOPES_DEFAULT_RANGE=inclusive ``` -------------------------------- ### Minutes Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Demonstrates using scopes to query transactions by minutes, covering specific intervals and custom minute counts. ```php // query by MINUTES Transaction::ofLastMinute(); // query transactions created during the last minute Transaction::ofLast15Minutes(); // query transactions created during the last 15 minutes Transaction::ofLast30Minutes(); // query transactions created during the last 30 minutes Transaction::ofLast45Minutes(); // query transactions created during the last 45 minutes Transaction::ofLast60Minutes(); // query transactions created during the last 60 minutes Transaction::ofLastMinutes(120); // query transactions created during the last N minutes ``` -------------------------------- ### Basic Usage of Date Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Demonstrates how to use the `DateScopes` trait in a Laravel Eloquent model and query records using various date scopes like `ofToday`, `ofLastWeek`, and `monthToDate`. Also shows chaining with aggregation methods. ```php use LaracraftTech\LaravelDateScopes\DateScopes; class Transaction extends Model { use DateScopes; } // query transactions created today Transaction::ofToday(); // query transactions created during the last week Transaction::ofLastWeek(); // query transactions created during the start of the current month till now Transaction::monthToDate(); // query transactions created during the last year, start from 2020 Transaction::ofLastYear(startFrom: '2020-01-01'); // ... and much more scopes are available (see below) // For sure, you can chain any Builder function you want here. // Such as these aggregations, for instance: Transaction::ofToday()->sum('amount'); Transaction::ofLastWeek()->avg('amount'); ``` -------------------------------- ### Weeks Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Demonstrates querying transactions by weeks using scopes, including last week, specific intervals, and custom week counts. ```php // query by WEEKS Transaction::ofLastWeek(); // query transactions created during the last week Transaction::ofLast2Weeks(); // query transactions created during the last 2 weeks Transaction::ofLast3Weeks(); // query transactions created during the last 3 weeks Transaction::ofLast4Weeks(); // query transactions created during the last 4 weeks Transaction::ofLastWeeks(8); // query transactions created during the last N weeks ``` -------------------------------- ### Fluent Date Range Configuration Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Demonstrates how to fluently specify inclusive or exclusive date ranges for scopes, overriding global defaults. ```php Transaction::ofLast7Days(customRange: DateRange::INCLUSIVE); ``` -------------------------------- ### Custom Created At Column Configuration Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Shows how to define a custom 'created_at' column name within an Eloquent model for date scope filtering. ```php use LaracraftTech\LaravelDateScopes\DateScopes; class Transaction extends Model { use DateScopes; public $timestamps = false; const CREATED_AT = 'custom_created_at'; } ``` -------------------------------- ### Custom Datetime Column for Scopes Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Explains how to specify a different datetime column than the default 'created_at' when using date scopes. ```php Transaction::ofToday(column: 'approved_at') ``` -------------------------------- ### Query by Quarters Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on the last N quarters. Supports specific quarters and a range of quarters. ```php Transaction::ofLastQuarter(); // query transactions created during the last quarter Transaction::ofLast2Quarters(); // query transactions created during the last 2 quarters Transaction::ofLast3Quarters(); // query transactions created during the last 3 quarters Transaction::ofLast4Quarters(); // query transactions created during the last 4 quarters Transaction::ofLastQuarters(8); // query transactions created during the last N quarters ``` -------------------------------- ### Query by Months Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on the last N months. Supports specific months and a range of months. ```php Transaction::ofLastMonth(); // query transactions created during the last month Transaction::ofLast3Months(); // query transactions created during the last 3 months Transaction::ofLast6Months(); // query transactions created during the last 6 months Transaction::ofLast9Months(); // query transactions created during the last 9 months Transaction::ofLast12Months(); // query transactions created during the last 12 months Transaction::ofLastMonths(24); // query transactions created during the last N months ``` -------------------------------- ### Query by Years Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on the last N years. Supports the last year and a range of years. ```php Transaction::ofLastYear(); // query transactions created during the last year Transaction::ofLastYears(2); // query transactions created during the last N years ``` -------------------------------- ### Query Time Ranges to Now/Date Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on time ranges relative to the current second, minute, hour, day, week, month, quarter, year, decade, century, or millennium. ```php Transaction::secondToNow(); // query transactions created during the start of the current second till now (equivalent of just now) Transaction::minuteToNow(); // query transactions created during the start of the current minute till now Transaction::hourToNow(); // query transactions created during the start of the current hour till now Transaction::dayToNow(); // query transactions created during the start of the current day till now Transaction::weekToDate(); // query transactions created during the start of the current week till now Transaction::monthToDate(); // query transactions created during the start of the current month till now Transaction::quarterToDate(); // query transactions created during the start of the current quarter till now Transaction::yearToDate(); // query transactions created during the start of the current year till now Transaction::decadeToDate(); // query transactions created during the start of the current decade till now Transaction::centuryToDate(); // query transactions created during the start of the current century till now Transaction::millenniumToDate(); // query transactions created during the start of the current millennium till now ``` -------------------------------- ### Query by Millenniums Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on the last N millenniums. Note the specific date range behavior for millenniums. ```php Transaction::ofLastMillennium(); // query transactions created during the last millennium Transaction::ofLastMillenniums(2); // query transactions created during the last N millenniums ``` -------------------------------- ### Query by Decades Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on the last N decades. Supports the last decade and a range of decades. ```php Transaction::ofLastDecade(); // query transactions created during the last decade Transaction::ofLastDecades(2); // query transactions created during the last N decades ``` -------------------------------- ### Query by Centuries Source: https://github.com/laracraft-tech/laravel-date-scopes/blob/main/README.md Query Eloquent models based on the last N centuries. Note the specific date range behavior for centuries. ```php Transaction::ofLastCentury(); // query transactions created during the last century Transaction::ofLastCenturies(2); // query transactions created during the last N centuries ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.