radfusion/app/helpers.php
2025-01-01 13:05:34 +06:00

61 lines
1.3 KiB
PHP

<?php
use App\Models\User;
use App\Services\AuditTrail\ActivityLogger;
if (! function_exists('_h')) {
function _h(int $key): string
{
return Hashids::encode($key);
}
}
if (! function_exists('unhash_it')) {
function unhash_it(string $hashid): int
{
return (int) Hashids::decode($hashid)[0];
}
}
if (! function_exists('audit')) {
function audit(): ActivityLogger
{
return app(ActivityLogger::class);
}
}
if (! function_exists('array_purge')) {
function array_purge(array $ary): array
{
return array_filter($ary, fn ($v) => filled($v));
}
}
if (! function_exists('sync_agent_id')) {
function sync_agent_id(): int
{
return cache()->rememberForever('sync_agent_id',
fn () => User::where('username', '$$_pacs_sync_$$')->first()->id);
}
}
if (! function_exists('user_per_page')) {
function user_per_page(?int $user_id = null): int
{
$user_id = (int) ($user_id ?? auth()->id());
return settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
}
}
if (! function_exists('may')) {
function may(BackedEnum|iterable|string $perm): bool
{
if (auth()->user()->isAdmin()) {
return true;
}
return auth()->user()->can($perm);
}
}