目前,我可以从items表中提取所有产品,但由于在SizesToProducts表中设置了关系,我无法匹配sizes_id
。
数据库表如下:
以下是我的模特:
//--- Item Class
class Item extends \Eloquent {
protected $table = '_cart_item';
function product()
{
return $this->hasMany('App\Models\Product','id');
}
}
//--- Product Class
class Product extends \Eloquent {
protected $table = '_products';
public function items()
{
return $this->belongsTo('Item');
}
public function size()
{
return $this->hasMany('Product','product_id');
}
}
//--- Size Class
class Size extends \Eloquent {
protected $table = '_sizes';
public function product()
{
return $this->belongsTo('SizeToProduct','sizes_id');
}
}
//--- SizeToProduct Class
class SizeToProduct extends \Eloquent {
protected $table = '_sizes_to_products';
public function items()
{
return $this->belongsTo('Product','sizes_id');
}
}