12-05-2026 Frontend dev
This commit is contained in:
parent
405df0a122
commit
5b8bdf4182
779 changed files with 480564 additions and 6241 deletions
86
app/Models/PressReleaseImage.php
Normal file
86
app/Models/PressReleaseImage.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PressReleaseImage extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'press_release_id',
|
||||
'disk',
|
||||
'path',
|
||||
'variants',
|
||||
'title',
|
||||
'description',
|
||||
'copyright',
|
||||
'is_preview',
|
||||
'sort_order',
|
||||
'width',
|
||||
'height',
|
||||
'mime',
|
||||
'legacy_portal',
|
||||
'legacy_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'variants' => 'array',
|
||||
'is_preview' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
'width' => 'integer',
|
||||
'height' => 'integer',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function pressRelease(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PressRelease::class);
|
||||
}
|
||||
|
||||
public function url(): ?string
|
||||
{
|
||||
if (blank($this->path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveDiskUrl($this->path);
|
||||
}
|
||||
|
||||
public function variantUrl(string $key): ?string
|
||||
{
|
||||
$variantPath = $this->variants[$key] ?? null;
|
||||
|
||||
if (! is_string($variantPath) || blank($variantPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveDiskUrl($variantPath);
|
||||
}
|
||||
|
||||
private function resolveDiskUrl(string $relativePath): ?string
|
||||
{
|
||||
if ($this->disk === 'public') {
|
||||
return asset('storage/'.ltrim($relativePath, '/'));
|
||||
}
|
||||
|
||||
try {
|
||||
$disk = Storage::disk($this->disk);
|
||||
|
||||
if (method_exists($disk, 'url')) {
|
||||
return $disk->url($relativePath);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue