Created
November 11, 2021 19:36
-
-
Save Braunson/f8ea23a39f700d98eddc50c31d614597 to your computer and use it in GitHub Desktop.
whereBetweenDates macro scope for Laravel 8x.
This file contains 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
<?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