24 lines
515 B
PHP
24 lines
515 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class PostImage extends Model
|
|
{
|
|
protected $fillable = ['post_id', 'filename', 'sort_order'];
|
|
|
|
public function post()
|
|
{
|
|
return $this->belongsTo(Post::class);
|
|
}
|
|
|
|
public function getImageUrlAttribute(): string
|
|
{
|
|
if (str_starts_with($this->filename, 'users/')) {
|
|
return route('media.post-image', $this->filename);
|
|
}
|
|
return asset('storage/post_images/' . $this->filename);
|
|
}
|
|
}
|