Skip to content

vantageoy/period-queries

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel period queries

Adds overlaps and intersects macros to your Illuminate\Database\Query\Builder.

Period relations

Installation

Just composer require vantage/period-queries

Usage

<?php

use Illuminate\Database\Eloquent\Model;

class Event extends Model
{
    /**
     * The attributes that should be mutated to dates.
     */
    protected $dates = ['started_at', 'ended_at'];

    /**
     * The attributes that are mass assignable.
     */
    protected $fillable = ['started_at', 'ended_at'];
}
use Carbon\CarbonPeriod;

$period = CarbonPeriod::create('2019-01-01', '2019-01-31');

Event::overlaps($period);
$start = new DateTime(2019, 1, 1);
$end = new DateTime(2019, 1, 31);
$period = new DatePeriod($start, 'P1D', $end);

Event::intersects($period);

Advanced

Event::whereTitle($title)->orOverlaps($period);
Event::whereTitle($title)->orIntersects($period);
Event::overlaps($period, ['created_at', 'updated_at']);

Contributing

  1. composer install
  2. ./vendor/bin/phpunit

About

Query by overlapping and intersecting periods in Laravel

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages