Files
boursecu_server/app/Models/File.php
T

65 lines
1.4 KiB
PHP
Raw Normal View History

2026-02-16 09:29:37 +00:00
<?php
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;
2026-06-29 19:58:06 +03:30
2026-02-16 09:29:37 +00:00
protected $fillable = [
'original_name',
'title',
'ext',
'src',
'size',
'user_id',
'type',
'has_thumb',
'url',
];
2026-06-29 19:58:06 +03:30
2026-02-16 09:29:37 +00:00
protected $casts = [
2026-06-29 19:58:06 +03:30
'has_thumb' => 'boolean',
2026-02-16 09:29:37 +00:00
];
2026-06-29 19:58:06 +03:30
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, '/'));
2026-02-16 09:29:37 +00:00
}
}