laravel-date-scopes maintained by jingulab
Laravel Date Scopes
A lightweight Laravel package that provides convenient date-based Eloquent scopes for your models.
Requirements
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
Installation
You can install the package via Composer:
composer require jingulab/laravel-date-scopes
Usage
Add the HasDateScopes trait to your Eloquent model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Jingulab\LaravelDateScopes\Traits\HasDateScopes;
class Post extends Model
{
use HasDateScopes;
}
Available Scopes
Now you can easily query records by date:
// Filter by specific dates or ranges
$todayPosts = Post::whereToday()->get();
$yesterdayPosts = Post::whereYesterday()->get();$thisMonthPosts = Post::whereThisMonth()->get();
// Custom column support (default is 'created_at')
$publishedToday = Post::whereToday('published_at')->get();
Testing
Run tests using PHPUnit:
composer test
License
The MIT License (MIT). Please see License File for more information.