<?php

class Office extends ContentTypeModel
{
    use LanguageSupportTrait;

    protected $hidden = array('languages', "websites");
    protected $with = array("websites", "languages");

    public function contact()
    {
        return $this->belongsTo("Contact");
    }

    public function country()
    {
        return $this->belongsTo("Country");
    }

    public function scopeFilterByContinent($query, $continent)
    {
        return $query->whereExists(function ($query) use ($continent) {
            $query->select(DB::raw(1))
                ->from("countries")
                ->whereRaw("countries.id = offices.country_id")
                ->where("countries.continent", $continent);
        });
    }

    public function overviewImage()
    {
        return $this->belongsTo("MediaItem");
    }
}
