<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class Hosea extends Model implements HasMedia
{
    use InteractsWithMedia;

    protected $table = 'hosea_page';
    protected $hidden = ['created_at', 'updated_at'];
    protected $guarded = array();
    protected $casts = [
        'related_article' => 'array',
    ];

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
            ->width(130)
            ->height(130);
    }

    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('main')->singleFile();
        $this->addMediaCollection('my_multi_collection');
    }

    public function scopeActive($query)
    {
        return $query->where('active', true);
    }

    public function get_image()
    {
        return $this->hasMany(Media::class, 'model_id')->select(['*']);
    }

    //public function article()
    //{
    //    return $this->hasMany(Article::class, 'id');
    //}
}
