Created
May 20, 2019 23:42
-
-
Save fcaldarelli/bdc782be7b48aa91e25bb4ac22fa779f to your computer and use it in GitHub Desktop.
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
<?php | |
class DateTraitQuery | |
{ | |
public function andWhereDate($attribute, $value, $separators = ['/','-']) | |
{ | |
$array = null; | |
foreach($separators as $separator) | |
{ | |
if(strpos($value, $separator) !== false) $array = explode($separator, $value); | |
} | |
if($array == null) $array = [ $value ]; | |
$this->andWhere(['like', $attribute, implode('-', array_reverse($array))]); | |
} | |
public function andFilterWhereDate($attribute, $value, $separators = ['/','-']) | |
{ | |
if($value) | |
{ | |
$this->andWhereDate($attribute, $value, $separators); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment