File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -29,9 +29,26 @@ public static function getApiUrl(string $path, array $queryParams = []): string
2929 return self ::addQueryParamsToUrl ($ queryParams , $ url );
3030 }
3131
32+ /**
33+ * Generates a CDN URL for the given path if a CDN URL is configured.
34+ * Falls back to generating a URL using the specified or default filesystem disk.
35+ *
36+ * @param string $path The relative path to the asset.
37+ * @return string The fully qualified URL to the asset, either via CDN or storage disk.
38+ */
3239 public static function getCdnUrl (string $ path ): string
3340 {
34- return config ('app.cnd_url ' ) . '/ ' . $ path ;
41+ // Fetch the CDN URL from environment variables
42+ // Checking against the env variable instead of config() as config falls back to the default value
43+ // and we want to ensure that if the env variable is not set, we do not use a default value.
44+ $ envCDNUrl = env ('APP_CDN_URL ' );
45+
46+ if ($ envCDNUrl ) {
47+ return $ envCDNUrl . '/ ' . $ path ;
48+ }
49+
50+ $ disk = config ('filesystems.public ' , 'public ' );
51+ return app ('filesystem ' )->disk ($ disk )->url ($ path );
3552 }
3653
3754 private static function addQueryParamsToUrl (array $ queryParams , mixed $ url ): mixed
You can’t perform that action at this time.
0 commit comments