lundi 16 avril 2018

Laravel BelongsToMany with two pivot table

I have the following table structure:

products

  • id

product_formats

  • id
  • product_id

product_prices

  • id
  • product_format_id
  • market_id

markets

  • id

A product can have multiple formats, with each having their own price which belongs in a different market. How can I retrieve the list of Markets from the Product model?

I used to have a single pivot table, however now I have two pivot.

class Product extends Model
{
    public function markets()
    {
        return $this->belongsToMany(Market::class);
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire