<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

/**
 * Class Review.
 *
 * @package namespace App\Models;
 */
class Blog extends Model implements Transformable, HasMedia
{
    use TransformableTrait;
    use InteractsWithMedia;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'heading',
        'description',
        'user_id'
    ];

    public function blogImage($mediaType)
    {
        $media = $this->getMedia($mediaType)->first();
        if ($media) {
            return $media->getUrl();
        }
        return asset('upload/No-Image.png');
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

}
