<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Astrotomic\Translatable\Translatable;

class WebinarForItem extends Model implements TranslatableContract
{
    use Translatable;

    protected $table = 'webinar_for_items';
    protected $primaryKey = 'id';
    public $incrementing = true;
    protected $keyType = 'int';
    public $timestamps = true;
    protected $fillable = ['webinar_id', 'bundle_id', 'image', 'icon', 'background_color'];
    public $translatedAttributes = ['description'];
    
    public function getDescriptionAttribute()
    {
        return getTranslateAttributeValue($this, 'description');
    }
    
    public function getImage()
    {
        if (empty($this->image)) {
            return null;
        }

        if (preg_match('/^https?:\/\//i', $this->image)) {
            return $this->image;
        }

        $base = rtrim(config('app.url', url('/')), '/');
        $path = ltrim($this->image, '/');

        return $base . '/' . $path;
    }
}
