id(); return Cache::remember($cacheKey, now()->addMinutes(0), function() use ($resourceType, $resourceValue, $permission) { try { return DB::table('auth.vw_user_authorizations') ->where('user_id', auth()->id()) ->where('resource_type', $resourceType) ->where('resource_value', $resourceValue) ->where('permission_name', $permission) ->exists(); } catch (\Exception $e) { Log::error('Authorization check failed', [ 'error' => $e->getMessage(), 'user_id' => auth()->id(), 'resource_type' => $resourceType, 'resource_value' => $resourceValue, 'permission' => $permission ]); return false; } }); } /** * Get all resources of a specific type that the user has permission to access * * @param string $resourceType * @param string $resourceValue * @param string $permission * @return array */ public function getAuthorizedResourceIds(string $resourceType, string $resourceValue, string $permission): array { try { return DB::table('auth.vw_user_authorizations') ->where('user_id', auth()->id()) ->where('resource_type', $resourceType) ->where('resource_value', $resourceValue) ->where('permission_name', $permission) ->pluck('resource_id') ->filter() ->toArray(); } catch (\Exception $e) { Log::error('Failed to get authorized resource IDs', [ 'error' => $e->getMessage(), 'user_id' => auth()->id(), 'resource_type' => $resourceType, 'resource_value' => $resourceValue, 'permission' => $permission ]); return []; } } }