librevlad/magic-dates

Work in progress

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

This package is auto-updated.

Last update: 2024-08-30 01:49:35 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).