create PM v0.5
This commit is contained in:
parent
9b47296cea
commit
d2ba22c0cf
25 changed files with 2155 additions and 72 deletions
67
app/Models/PressReleaseAttachment.php
Normal file
67
app/Models/PressReleaseAttachment.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\PressReleaseAttachmentFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PressReleaseAttachment extends Model
|
||||
{
|
||||
/** @use HasFactory<PressReleaseAttachmentFactory> */
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'press_release_id',
|
||||
'disk',
|
||||
'path',
|
||||
'original_name',
|
||||
'mime',
|
||||
'size',
|
||||
'title',
|
||||
'description',
|
||||
'sort_order',
|
||||
'legacy_portal',
|
||||
'legacy_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'size' => 'integer',
|
||||
'sort_order' => 'integer',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function pressRelease(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PressRelease::class);
|
||||
}
|
||||
|
||||
public function url(): ?string
|
||||
{
|
||||
if (blank($this->path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->disk === 'public') {
|
||||
return asset('storage/'.ltrim((string) $this->path, '/'));
|
||||
}
|
||||
|
||||
try {
|
||||
$disk = Storage::disk($this->disk);
|
||||
|
||||
if (method_exists($disk, 'url')) {
|
||||
return $disk->url($this->path);
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue