librevlad / magic-dates
Work in progress
dev-master
2023-02-03 20:34 UTC
Requires (Dev)
- phpunit/phpunit: 8.*
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2025-03-01 00:23:52 UTC
README
Adds magic methods to your Eloquent query builder to work with dates.
Installation
You can install the package via composer:
composer require librevlad/magic-dates
Usage
Works only with fields explicitly declared on the $dates property of your model.
class Order extends Model { protected $dates = [ 'created_at', 'updated_at', 'shipped_at', ]; /** **/ }
// same thing as ->where('created_at','>', now()->subWeek() ) $orders = Order::createdSince( now()->subWeek() ); // same thing as ->where('updated_at','>', now()->subWeek() ) $orders = Order::updatedAfter( now()->subWeek() ); // same thing as ->whereBetween('shipped_at', now()->subWeek(), now() ) $orders = Order::shippedBetween( now()->subYear(), now() );
Testing
composer test
License
The MIT License (MIT).