fix pictures

This commit is contained in:
2026-06-29 19:58:06 +03:30
parent 8fc71a1281
commit c177bdbb22
6 changed files with 72 additions and 31 deletions
+37 -5
View File
@@ -5,12 +5,12 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Setting;
class File extends Model
{
use HasFactory;
use Selector;
protected $fillable = [
'original_name',
'title',
@@ -22,11 +22,43 @@ class File extends Model
'has_thumb',
'url',
];
protected $casts = [
"has_thumb"=>"boolean"
'has_thumb' => 'boolean',
];
public function getSrcAttribute(){
return env('domain').$this->attributes['src'];
// return url($this->attributes['src']);
protected $appends = [
'full_src',
];
/**
* مسیر نسبی ذخیره‌شده در DB — بدون پیشوند دامنه.
*/
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 static function publicUrl(?string $path): ?string
{
if ($path === null || trim($path) === '') {
return null;
}
$trimmed = trim($path);
if (preg_match('/^https?:\/\//i', $trimmed)) {
return $trimmed;
}
return asset(ltrim($trimmed, '/'));
}
}