<?php

namespace App\Models\Botanic;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Wildside\Userstamps\Userstamps;

class Family extends Model
{
    use HasRelationships, SoftDeletes, Userstamps;

    protected $guarded = ['id'];

    protected $table = 'botanic_families';

    public function genres()
    {
        return $this->hasMany('App\Models\Botanic\Genre');
    }

    public function species()
    {
        return $this->hasManyThrough('App\Models\Botanic\Specie', 'App\Models\Botanic\Genre');
    }

    public function varieties()
    {
        return $this->hasManyDeep('App\Models\Botanic\Variety', ['App\Models\Botanic\Genre', 'App\Models\Botanic\Specie']);
    }

    public function scopeByName($query, $name)
    {
        return $query->where('name', $name);
    }
}
