fix pictures 2
This commit is contained in:
@@ -78,7 +78,7 @@ class ProductController extends SuperController
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if ($product->relationLoaded('file') && $product->file) {
|
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) {
|
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\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
||||||
|
|
||||||
class File extends Model
|
class File extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory, Selector;
|
||||||
use Selector;
|
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'original_name',
|
'original_name',
|
||||||
@@ -32,21 +30,22 @@ class File extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* مسیر نسبی ذخیرهشده در DB — بدون پیشوند دامنه.
|
* URL کامل تصویر — همان قرارداد قبلی API (src = آدرس قابل نمایش).
|
||||||
*/
|
*/
|
||||||
public function getSrcAttribute(): ?string
|
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);
|
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
|
public static function publicUrl(?string $path): ?string
|
||||||
{
|
{
|
||||||
if ($path === null || trim($path) === '') {
|
if ($path === null || trim($path) === '') {
|
||||||
@@ -59,6 +58,8 @@ class File extends Model
|
|||||||
return $trimmed;
|
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;
|
$fileModel = $product->file;
|
||||||
$relativeSrc = (string) ($fileModel->getAttributes()['src'] ?? '');
|
$src = (string) ($fileModel->src ?? '');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $fileModel->id,
|
'id' => $fileModel->id,
|
||||||
'src' => $relativeSrc,
|
'src' => $src,
|
||||||
'full_src' => \App\Models\File::publicUrl($relativeSrc),
|
'full_src' => $src,
|
||||||
'url' => $fileModel->url ?? null,
|
'url' => $fileModel->url ?? null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user