Download the PHP package greenimp/laravel-date-range without Composer
On this page you can find all versions of the php package greenimp/laravel-date-range. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download greenimp/laravel-date-range
More information about greenimp/laravel-date-range
Files in greenimp/laravel-date-range
Package laravel-date-range
Short Description Easy handling of Laravel models that have a to / from date
License MIT
Homepage https://github.com/GreenImp/laravel-date-range
Informations about the package 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
Install
Set up the DB
If you want to use 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:
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:
Configuring the package
Publishing the config file is optional:
Usage
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:
An example migration for the model:
Multiple date ranges
If your model has multiple date ranges (e.g. A repeating event such as a national holiday), the model must implement the
HasDateRanges
interface, and the InteractsWithDateRanges
trait.
The trait adds a new dates
relationship, which links to the list of date ranges.
Note: Unless you're using a run the migration.
Customisation
Custom Date Range model
By default, the dates
relationship on the InteractsWithDateRanges
trait, for multiple date ranges, will use the
DateRange
model that comes with this package.
If you want to use your own custom class, you can use any model that implements the HasDateRange
interface, and the
InteractsWithDateRange
trait.
To set up your custom model, follow the instructions for creating a single date range model.
You also need to update the config file, to use your custom class:
Database migration options
Table name
The migration file that comes with this package will create a table to store the DateRange
models in, called
date_ranges
.
You can change the name of the table in the config file:
Table columns
You can also rename the table columns that will be used in the migration.
Note: This will also affect the default field names for the start / end dates of the
DateRangeOptions
class, used in thegetDateRangeOptions
method.
All versions of laravel-date-range with dependencies
illuminate/database Version ^8.0|^9.0
illuminate/support Version ^8.0|^9.0
nesbot/carbon Version ^2.65