Skip to content

Instantly share code, notes, and snippets.

@aytacmalkoc
Last active January 12, 2025 06:12
Show Gist options
  • Save aytacmalkoc/a125dd5771a17e2c1c1e9aa34496f252 to your computer and use it in GitHub Desktop.
Save aytacmalkoc/a125dd5771a17e2c1c1e9aa34496f252 to your computer and use it in GitHub Desktop.
Laravel helper functions
<?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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment