dimanche 1 mai 2016

eloquent distant relations via many-to-many relation

have 3 tables: regions, countries, tours

region has countries and country is related to a region

tours have countries and countries have tours.

Now I need Region has tours and tour has regions (tour can include more than one region depending upon countries it belongs to)

I know "Has Many Through" but this is usable when intermediate relation is one-to-many but my intermediate relation is many-to-many

I tried this

public function tours()
{
    return $this->hasManyThrough(Tour::class, Country::class, "region_id", "country_id");
}

but "country_id" is not available in Tours table. Because Tours and Countries have many-to-many relation and country_id is in pivot table.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/24hygKS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire