Last active
February 11, 2022 20:02
-
-
Save shawnlindstrom/676ccac3eabbae8f1c9893533ac04501 to your computer and use it in GitHub Desktop.
Laravel Builder Macro for whereBetweenDates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Add to your \App\Providers\AppServiceProvider.php or php artisan make:provider MacroServiceProvider | |
* and register your new provider in config/app.php | |
*/ | |
public function register() | |
{ | |
\Illuminate\Database\Eloquent\Builder::macro('whereBetweenDates', function (string $column, array $values) { | |
[$start, $end] = $values; | |
return $this->getQuery() | |
->whereDate($column, '>=', $start) | |
->whereDate($column, '<=', $end); | |
}); | |
\Illuminate\Database\Query\Builder::macro('whereBetweenDates', function (string $column, array $values) { | |
[$start, $end] = $values; | |
return $this | |
->whereDate($column, '>=', $start) | |
->whereDate($column, '<=', $end); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment