belongsTo(ProductModel::class, 'related_product_id', 'id'); } // 根据产品ID查询 public function scopeProductId($query, $id) { if (is_array($id)) { $query->where('product_id', 'in', $id); return; } $query->where('product_id', '=', $id); } }