Problem with DDBB MySQL and Eloquen relationship

0

I have 3 Models (tables) in the development of a web page:

* Article *Colour * Size

The tables must be related since "Article" can have several colors and several sizes. The problem is that there must be a "Quantity" field that I do not know where to put it. When selecting an item and selecting a color, all available sizes must be presented for the selected color.

    
asked by Oswald Morales 12.08.2018 в 04:13
source

1 answer

-1

You must use the Many to Many relationship with Pivot

class Articulo extends Model
{
    public function tallas()
    {
        return $this->belongsToMany(Talla::class, 'articulo_talla_color')->withPivot('color_id', 'cantidad');
    }

    public function colores()
    {
        return $this->belongsToMany(Talla::class, 'articulo_talla_color')->withPivot('talla_id', 'cantidad');
    }
}

Retrieving Intermediate Table Columns

    
answered by 13.08.2018 в 22:48