Skip to main content
Back to packages
514 GitHub stars

laracraft-tech/laravel-date-scopes

View on GitHub

Description

Provides a big range of useful date scopes for your Laravel Eloquent models.

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:

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

Related Content on Laravel Daily

Video

Recent Courses on Laravel Daily