}
/**
- * Gets a public facing url for an image by checking relevant environment variables.
+ * Gets a public facing url for an image or location at the given path.
+ */
+ public static function getPublicUrl(string $filePath): string
+ {
+ return static::getPublicBaseUrl() . '/' . ltrim($filePath, '/');
+ }
+
+ /**
+ * Get the public base URL used for images.
+ * Will not include any path element of the image file, just the base part
+ * from where the path is then expected to start from.
* If s3-style store is in use it will default to guessing a public bucket URL.
*/
- public function getPublicUrl(string $filePath): string
+ protected static function getPublicBaseUrl(): string
{
$storageUrl = config('filesystems.url');
$basePath = $storageUrl ?: url('/');
- return rtrim($basePath, '/') . $filePath;
+ return rtrim($basePath, '/');
}
}