Risolvere il problema HasManyTriple
A volte ti trovi nella situazione in cui hai una tabella come shop_country_category, che ha la seguente struttura:
paesi - id - nome negozio - id - nome prodotti - id - nome negozio_paese_prodotto - id - id_paese - id_negozio - id_prodotto
In questo caso un negozio ha prodotti specifici che differiscono per Paese. Quindi, ad esempio nel modello Shop.php Eloquent usa:
/** * I prodotti specifici del paese che appartengono a un negozio (relazione a triplo pivot) */ public function countryProducts() { return $this->belongsToMany('App\Product','shop_country_product') ->withPivot('country_id'); }
In questo modo puoi accedere a quella categoria shop_country_category
Oppure usa un plugin
Non l'ho testato, ma ho sentito questo pacchetto potrebbe funzionare con Laravel 5.
Hai una soluzione migliore?
Non esitate a condividerli nei commenti.