Skip to main content
Back to packages
515 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

Roles and Permissions in Laravel 13

14 lessons
57 min

Queues in Laravel 13

18 lessons
1 h 12 min read

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.