primitive/flexible-where-between

0.2 2020-11-26 16:35 UTC

This package is auto-updated.

Last update: 2024-11-27 00:51:16 UTC


README

Latest Version on Packagist Total Downloads

image

We created this package to avoid duplication of code accross projects when using Laravel's whereBetween method.

For example, if you are looking for "something" between two dates, your method without this package would need to look like:

$logs = Log::query();

if ((empty($end_date) && (empty($start_date))
{
    $logs = $logs->get();
}

else if (empty($end_date)) 
{
   $logs = $logs->where('created_at','>=', $start_date);
}
else if (empty($start_date)) 
{
   $logs = $logs->where('created_at','<=', $end_date);
} 
else 
{
   $logs = $logs->whereBetween('created_at', [$start_date, $end_date])
}

This package takes care of that logic for you. Your new method would look like:

Log::whereBetween('created_at', [$start_date, $end_date])

So, regardless of whether $start_date or $end_date is NULL or has a value, it will "just work".

Installation

You can install the package via composer:

composer require primitive/flexible-where-between

Usage

After the package is installed, a macro is registered that overrides the default whereBetween functionality. So, it just works. :)

Credits

License

The MIT License (MIT). Please see License File for more information.