fix pictures 2
This commit is contained in:
@@ -78,7 +78,7 @@ class ProductController extends SuperController
|
||||
]);
|
||||
|
||||
if ($product->relationLoaded('file') && $product->file) {
|
||||
$product->file->setAttribute('full_src', File::publicUrl($product->file->getAttributes()['src'] ?? null));
|
||||
$product->file->setAttribute('full_src', $product->file->src);
|
||||
}
|
||||
|
||||
if ($representativeId !== null && (int) $product->id === $representativeId) {
|
||||
|
||||
+14
-13
@@ -4,12 +4,10 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class File extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Selector;
|
||||
use HasFactory, Selector;
|
||||
|
||||
protected $fillable = [
|
||||
'original_name',
|
||||
@@ -32,21 +30,22 @@ class File extends Model
|
||||
];
|
||||
|
||||
/**
|
||||
* مسیر نسبی ذخیرهشده در DB — بدون پیشوند دامنه.
|
||||
* URL کامل تصویر — همان قرارداد قبلی API (src = آدرس قابل نمایش).
|
||||
*/
|
||||
public function getSrcAttribute(): ?string
|
||||
{
|
||||
return $this->attributes['src'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL کامل قابل نمایش در مرورگر (بر اساس APP_URL و symlink storage).
|
||||
*/
|
||||
public function getFullSrcAttribute(): ?string
|
||||
{
|
||||
return self::publicUrl($this->attributes['src'] ?? null);
|
||||
}
|
||||
|
||||
public function getFullSrcAttribute(): ?string
|
||||
{
|
||||
return $this->src;
|
||||
}
|
||||
|
||||
/**
|
||||
* ساخت URL عمومی از مسیر نسبی storage/...
|
||||
* قبلاً: env('domain') + path — بدون اسلش بین دامنه و مسیر خراب میشد.
|
||||
*/
|
||||
public static function publicUrl(?string $path): ?string
|
||||
{
|
||||
if ($path === null || trim($path) === '') {
|
||||
@@ -59,6 +58,8 @@ class File extends Model
|
||||
return $trimmed;
|
||||
}
|
||||
|
||||
return asset(ltrim($trimmed, '/'));
|
||||
$domain = rtrim((string) (env('domain') ?: config('app.url')), '/');
|
||||
|
||||
return $domain.'/'.ltrim($trimmed, '/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,12 +646,12 @@ class AssetSummaryService
|
||||
}
|
||||
|
||||
$fileModel = $product->file;
|
||||
$relativeSrc = (string) ($fileModel->getAttributes()['src'] ?? '');
|
||||
$src = (string) ($fileModel->src ?? '');
|
||||
|
||||
return [
|
||||
'id' => $fileModel->id,
|
||||
'src' => $relativeSrc,
|
||||
'full_src' => \App\Models\File::publicUrl($relativeSrc),
|
||||
'src' => $src,
|
||||
'full_src' => $src,
|
||||
'url' => $fileModel->url ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user