librevlad/magic-dates

Work in progress

Installs: 52

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/librevlad/magic-dates

dev-master 2023-02-03 20:34 UTC

This package is auto-updated.

Last update: 2025-09-29 02:28:46 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).