diff --git a/app/Http/Controllers/Customer/ProductController.php b/app/Http/Controllers/Customer/ProductController.php index 310446c..42c695d 100644 --- a/app/Http/Controllers/Customer/ProductController.php +++ b/app/Http/Controllers/Customer/ProductController.php @@ -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) { diff --git a/app/Models/File.php b/app/Models/File.php index 3cc16f1..39a21e1 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -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, '/'); } } diff --git a/app/Services/AssetSummaryService.php b/app/Services/AssetSummaryService.php index d8192db..db2074a 100644 --- a/app/Services/AssetSummaryService.php +++ b/app/Services/AssetSummaryService.php @@ -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, ]; }