Last active
May 20, 2025 08:33
-
-
Save aytacmalkoc/a125dd5771a17e2c1c1e9aa34496f252 to your computer and use it in GitHub Desktop.
Laravel helper functions
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 | |
if (!function_exists('route_is')) { | |
function route_is(string|array $routeNames): bool | |
{ | |
$currentRoute = \Illuminate\Support\Facades\Route::currentRouteName(); | |
$routeNames = (array) $routeNames; | |
return collect($routeNames)->contains(fn($routeName) => \Illuminate\Support\Str::is($routeName, $currentRoute)); | |
} | |
} | |
if (!function_exists('route_with_query')) { | |
function route_with_query($name, $parameters = [], $absolute = true): string | |
{ | |
return route($name, [request()->getQueryString(), ...$parameters], $absolute); | |
} | |
} | |
if (!function_exists('get_hours_24_format')) { | |
function get_hours_24_format(): array | |
{ | |
$hours = []; | |
for ($i = 0; $i < 24; $i++) { | |
$hours[] = str_pad($i, 2, '0', STR_PAD_LEFT) . ':00'; | |
} | |
return $hours; | |
} | |
} | |
if (!function_exists('greeting')) { | |
function greeting(): string | |
{ | |
$hour = \Illuminate\Support\Carbon::now()->hour; | |
return match (true) { | |
$hour >= 6 && $hour < 12 => "🌥️ Günaydın", | |
$hour >= 12 && $hour < 18 => "😎 İyi günler", | |
$hour >= 18 && $hour < 23 => "🌚 İyi akşamlar", | |
$hour >= 23 || $hour < 6 => "🌜 İyi geceler" | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment