我有这两张桌子:
产品表:
name - price - quantity - etc
折扣表:
type('percentage','numeric') - value - cancel - expired_at
多态关系:可贴现表:
discount_id - discountable_id - discountable_type
他们之间有。所以我需要得到所有的产品,除了已经有折扣+有折扣的产品,但它结束了Many To Many (Polymorphic)expired_at
产品型号:
public function discounts()
{
return $this->morphToMany('App\Models\Discount', 'discountable');
}
折扣模式:
public function products()
{
return $this->morphedByMany('App\Models\Product', 'discountable')->withTimestamps();
}
我的错误关闭!
public function index()
{
$products = Product::with('discounts');
return view('cp.discounts.index', compact('products'));
}
慕侠2389804