PHPackages                             greenimp/laravel-date-range - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. greenimp/laravel-date-range

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

greenimp/laravel-date-range
===========================

Easy handling of Laravel models that have a to / from date

v2.1.4(3y ago)121MITPHPPHP ^8.0|8.1|8.2

Since Jan 23Pushed 3y ago1 watchersCompare

[ Source](https://github.com/GreenImp/laravel-date-range)[ Packagist](https://packagist.org/packages/greenimp/laravel-date-range)[ Docs](https://github.com/GreenImp/laravel-date-range)[ RSS](/packages/greenimp-laravel-date-range/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (13)Used By (0)

Laravel date range
==================

[](#laravel-date-range)

Easy handling of Laravel models that have a start / end date, or a set of date ranges.

This package is built for Laravel 8-9.

Setup
-----

[](#setup)

### Install

[](#install)

```
composer require "greenimp/laravel-date-range:^2.0.0"
```

### Set up the DB

[](#set-up-the-db)

If you want to use [multiple date ranges](#multiple-date-ranges) on a single model, then you need to create the DB tables, unless you are using a custom model.

First, publish the migrations:

```
php artisan vendor:publish --provider="GreenImp\DateRange\DateRangeServiceProvider" --tag="migrations"
```

The run them:

> **Note** If your config is cached, the migration will fail. You will need to clear the config cache **before** running the migration:
>
> ```
> php artisan config:clear
> ```

```
php artisan migrate
```

### Configuring the package

[](#configuring-the-package)

Publishing the [config file](./config/date-range.php) is optional:

```
php artisan vendor:publish --provider="GreenImp\DateRange\DateRangeServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

### Single date ranges

[](#single-date-ranges)

If your model only requires a single start / end date (e.g. a one off event), the model must implement the `HasDateRange` interface, and the `InteractsWithDateRange` trait.

The trait contains an abstract method `getDateRangeOptions`, which you must implement yourself.

Your models' migrations should have `datetime` fields to save the start / end dates to.

Here's an example of how to implement the trait:

```
