<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;

class Package extends Model
{
    protected $guarded = ['id'];

    protected $table = 'shop_packages';

    public function article_family()
    {
        return $this->belongsTo(ArticleNature::class);
    }

    public function unities()
    {
        return $this->hasMany(Unity::class);
    }

    public function variations()
    {
        return $this->hasMany(Variation::class);
    }

    public function offers()
    {
        return $this->hasManyThrough(Offer::class, Variation::class);
    }

    public function scopeByArticleNature($query, $id)
    {
        return $query->where($this->table.'.article_family_id', $id);
    }
}
