Last active
May 25, 2023 17:35
-
-
Save websterl3o/a804e7bd92ed11c678e302cc52520098 to your computer and use it in GitHub Desktop.
LaravelHelpers
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 | |
/** | |
* Return the SQL query with the bindings. | |
* | |
* @param \Illuminate\Database\Eloquent\Builder $query | |
* @return string | |
*/ | |
function getSql(Builder $query): string | |
{ | |
$bindings = $query->getBindings(); | |
return preg_replace_callback('/\?/', function ($match) use (&$bindings, $query) { | |
return $query->getConnection()->getPdo()->quote(array_shift($bindings)); | |
}, $query->toSql()); | |
} | |
/** | |
* Removes all non-numeric characters from a string. | |
* | |
* @param string $string | |
* @return string | |
*/ | |
function onlyNumbers($string): string | |
{ | |
return preg_replace('/\D/', '', $string); | |
} | |
/** | |
* Returns the next work day. | |
* | |
* @param Carbon|null $date | |
* @return Carbon | |
*/ | |
function nextWorkDay(Carbon $date = null) | |
{ | |
$date = $date ?? today(); | |
while ($date->isHoliday() || $date->isWeekend() || $date->isPast()) { | |
$date->addDay(); | |
} | |
return $date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment