user(); if(!$user) return false; return $user->hasRole($roles); } } if(!function_exists('roleName')) { function roleName($role): string { return Role::NAMES[$role] ?? (string) $role; } } if(!function_exists('hasPermission')) { function hasPermission(string $permission, $user = null): bool { if(!$user) $user = auth()->user(); if(!$user) return false; return $user->hasPermission($permission); } } if(!function_exists('hasAnyPermission')) { function hasAnyPermission(array|string $permissions, $user = null): bool { if(!$user) $user = auth()->user(); if(!$user) return false; return $user->hasAnyPermission($permissions); } } if(!function_exists('canViewField')) { function canViewField(string $module, string $field, ?string $entity = null, $user = null): bool { if(!$user) $user = auth()->user(); if(!$user) return false; return $user->canViewField($module, $field, $entity); } } if(!function_exists('canUpdateField')) { function canUpdateField(string $module, string $field, ?string $entity = null, $user = null): bool { if(!$user) $user = auth()->user(); if(!$user) return false; return $user->canUpdateField($module, $field, $entity); } } // return current year if(!function_exists('year')) { function year(): int { return (int)session('year', date('Y')); } } if(!function_exists('glob_safe')) { function glob_safe(string $str): string { return str_replace(['[', ']', '*', '?'], ['[[]', '[]]', '[*]', '[?]'], $str); } } if(!function_exists('fileName')) { function fileName($file): string { return preg_replace('/[\\*\\:\\\\\\/\\?<>]/', '_', $file); } }