primitive / flexible-where-between
0.2
2020-11-26 16:35 UTC
Requires
- php: ^7.1
- illuminate/support: ~7.0|~8.0
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
README
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.