<?php

namespace App\Models;

use Spatie\MediaLibrary\HasMedia;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\InteractsWithMedia;

class ImageGallery extends Model implements HasMedia
{
    use InteractsWithMedia;

    protected $table = "image_galleries";
    protected $fillable = ['title', 'status', 'sort'];
    protected $casts = [
        'id'          => 'integer',
        'title'       => 'string',
        'status'      => 'integer',
        'sort'        => 'integer'
    ];

    public function getImageAttribute(): string
    {
        if (!empty($this->getFirstMediaUrl('image-gallery'))) {
            return asset($this->getFirstMediaUrl('image-gallery'));
        }
        return asset('images/default/image-gallery.png');
    }
}
