Skip to content

Instantly share code, notes, and snippets.

@websterl3o
Last active May 25, 2023 17:35
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 websterl3o/a804e7bd92ed11c678e302cc52520098 to your computer and use it in GitHub Desktop.
Save websterl3o/a804e7bd92ed11c678e302cc52520098 to your computer and use it in GitHub Desktop.
LaravelHelpers
<?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