<?php

    namespace App\Models;

    use App\Libs\Database\Eloquent\ContentTypeModel;
    use App\Models\GenericBackoffice\Traits\LanguageSupportTrait;
    use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;

    class Block extends ContentTypeModel
    {
        use LanguageSupportTrait;
        use SpatialTrait;

        protected $hidden = ['languages', "websites"];
        protected $with = ['languages', "websites"];

        protected $dates = []; // dates
        protected $spatialFields = ['location']; // Locations lat & longs
        protected $casts = [];

        public function slider()
        {
            return $this->belongsToMany(SliderItem::class)->withPivot('position');
        }
            
        public function image()
        {
            return $this->belongsToMany(MediaItem::class, 'block_image', 'block_id', 'image_id');
        }

        public function tariffs()
        {
            return $this->belongsToMany(Tariff::class)->withPivot('position');
        }
    }
