+/**
+ * Get the path to a versioned file.
+ * @throws Exception
+ */
+function versioned_asset(string $file = ''): string
+{
+ static $version = null;
+
+ if (is_null($version)) {
+ $versionFile = base_path('version');
+ $version = trim(file_get_contents($versionFile));
+ }
+
+ $additional = '';
+ if (config('app.env') === 'development') {
+ $additional = sha1_file(public_path($file));
+ }
+
+ $path = $file . '?version=' . urlencode($version) . $additional;
+ return url($path);
+}
+
+/**
+ * Helper method to get the current User.
+ * Defaults to public 'Guest' user if not logged in.
+ */
+function user(): User
+{
+ return auth()->user() ?: User::getDefault();
+}
+
+/**
+ * Check if current user is a signed in user.
+ */
+function signedInUser(): bool
+{
+ return auth()->user() && !auth()->user()->isDefault();
+}
+
+/**
+ * Check if the current user has general access.
+ */
+function hasAppAccess(): bool
+{
+ return !auth()->guest() || setting('app-public');
+}
+
+/**
+ * Check if the current user has a permission. If an ownable element
+ * is passed in the jointPermissions are checked against that particular item.
+ */
+function userCan(string $permission, Model $ownable = null): bool
+{
+ if ($ownable === null) {
+ return user() && user()->can($permission);
+ }
+
+ // Check permission on ownable item
+ $permissionService = app(PermissionService::class);
+ return $permissionService->checkOwnableUserAccess($ownable, $permission);
+}
+
+/**
+ * Check if the current user has the given permission
+ * on any item in the system.
+ */
+function userCanOnAny(string $permission, string $entityClass = null): bool
+{
+ $permissionService = app(PermissionService::class);
+ return $permissionService->checkUserHasPermissionOnAnything($permission, $entityClass);
+}
+
+/**
+ * Helper to access system settings.
+ * @return bool|string|SettingService
+ */
+function setting(string $key = null, $default = false)
+{
+ $settingService = resolve(SettingService::class);
+
+ if (is_null($key)) {
+ return $settingService;
+ }