feat: add storage_url helper function and update image URL retrieval to use public disk
This commit is contained in:
@@ -31,3 +31,20 @@ if (!function_exists('hook')) {
|
||||
return \App\Helpers\EventHelper::renderEvent($event);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('storage_url')) {
|
||||
/**
|
||||
* Get the URL for a file stored on the public disk
|
||||
*
|
||||
* @param string|null $path
|
||||
* @return string|null
|
||||
*/
|
||||
function storage_url(?string $path): ?string
|
||||
{
|
||||
if (!$path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Illuminate\Support\Facades\Storage::disk('public')->url($path);
|
||||
}
|
||||
}
|
||||
24
app/Helpers/StorageHelper.php
Normal file
24
app/Helpers/StorageHelper.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class StorageHelper
|
||||
{
|
||||
/**
|
||||
* Get the URL for a file stored on the public disk
|
||||
*
|
||||
* @param string|null $path
|
||||
* @return string|null
|
||||
*/
|
||||
public static function url(?string $path): ?string
|
||||
{
|
||||
if (!$path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('public')->url($path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Index extends Component
|
||||
{
|
||||
return view('products.index')->layoutData([
|
||||
'title' => $this->category->name,
|
||||
'image' => $this->category->image ? Storage::url($this->category->image) : null,
|
||||
'image' => $this->category->image ? Storage::disk('public')->url($this->category->image) : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class Show extends Component
|
||||
{
|
||||
return view('products.show')->layoutData([
|
||||
'title' => $this->product->name,
|
||||
'image' => $this->product->image ? Storage::url($this->product->image) : null,
|
||||
'image' => $this->product->image ? Storage::disk('public')->url($this->product->image) : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class UserProfile extends Model
|
||||
public function getAvatarUrlAttribute(): ?string
|
||||
{
|
||||
if ($this->avatar_path) {
|
||||
return Storage::url($this->avatar_path);
|
||||
return Storage::disk('public')->url($this->avatar_path);
|
||||
}
|
||||
|
||||
// Return default avatar or gravatar
|
||||
@@ -135,7 +135,7 @@ class UserProfile extends Model
|
||||
public function getBannerUrlAttribute(): ?string
|
||||
{
|
||||
if ($this->banner_path) {
|
||||
return Storage::url($this->banner_path);
|
||||
return Storage::disk('public')->url($this->banner_path);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="flex items-center space-x-6">
|
||||
<div class="flex-shrink-0">
|
||||
@if($profile->avatar_path)
|
||||
<img src="{{ Storage::url($profile->avatar_path) }}"
|
||||
<img src="{{ Storage::disk('public')->url($profile->avatar_path) }}"
|
||||
alt="Current Avatar"
|
||||
class="h-20 w-20 rounded-full object-cover border-2 border-gray-300 dark:border-gray-600">
|
||||
@else
|
||||
@@ -69,7 +69,7 @@
|
||||
<div class="space-y-4">
|
||||
@if($profile->banner_path)
|
||||
<div class="relative">
|
||||
<img src="{{ Storage::url($profile->banner_path) }}"
|
||||
<img src="{{ Storage::disk('public')->url($profile->banner_path) }}"
|
||||
alt="Current Banner"
|
||||
class="w-full h-32 object-cover rounded-lg border border-gray-300 dark:border-gray-600">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user