Fixes
This commit is contained in:
@@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Creator Story model.
|
||||
@@ -143,11 +144,12 @@ class Story extends Model
|
||||
|
||||
public function getCoverUrlAttribute(): ?string
|
||||
{
|
||||
if (! $this->cover_image) {
|
||||
return null;
|
||||
}
|
||||
return $this->resolveStoryMediaUrl($this->cover_image);
|
||||
}
|
||||
|
||||
return str_starts_with($this->cover_image, 'http') ? $this->cover_image : asset($this->cover_image);
|
||||
public function getOgImageUrlAttribute(): ?string
|
||||
{
|
||||
return $this->resolveStoryMediaUrl($this->og_image);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,4 +176,30 @@ class Story extends Model
|
||||
|
||||
return \Illuminate\Support\Str::limit($text, 160);
|
||||
}
|
||||
|
||||
private function resolveStoryMediaUrl(?string $value): ?string
|
||||
{
|
||||
if (! $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (str_starts_with($value, 'http')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$path = ltrim($value, '/');
|
||||
if (str_starts_with($path, 'storage/')) {
|
||||
$path = substr($path, strlen('storage/'));
|
||||
}
|
||||
|
||||
if (preg_match('#^stories/(sm|md|original)/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]+\.(webp|jpg|jpeg|png)$#', $path) === 1) {
|
||||
$cdnBase = rtrim((string) config('cdn.files_url', ''), '/');
|
||||
|
||||
return $cdnBase !== ''
|
||||
? $cdnBase . '/' . $path
|
||||
: Storage::disk('public')->url($path);
|
||||
}
|
||||
|
||||
return asset($value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user