Skip to content

Instantly share code, notes, and snippets.

@Braunson
Created November 11, 2021 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Braunson/f8ea23a39f700d98eddc50c31d614597 to your computer and use it in GitHub Desktop.
Save Braunson/f8ea23a39f700d98eddc50c31d614597 to your computer and use it in GitHub Desktop.
whereBetweenDates macro scope for Laravel 8x.
<?php
public function boot()
{
// Extend the Query Builder
\lluminate\Database\Query\Builder::macro('whereBetweenDates', function($firstColumn, $secondColumn, $firstDate, $secondDate, $firstComparison = '>=', $secondComparison = '<=') {
return $this
->whereDate($firstColumn, $firstComparison, $firstDate)
->whereDate($secondColumn, $secondComparison, $secondDate);
});
// Extend the Eloquent Builder
\Illuminate\Database\Eloquent\Builder::macro('whereBetweenDates', function ($firstColumn, $secondColumn, $firstDate, $secondDate, $firstComparison = '>=', $secondComparison = '<=') {
return $this->getQuery()->whereBetweenDates($firstColumn, $secondColumn, $firstDate, $secondDate, $firstComparison, $secondComparison);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment