首页 > 解决方案 > 如何在多对多关系中获取枢轴数据

问题描述

我创建了 customer_products 表来存储 different_price 数据。现在我试图返回 different_price 来显示数据。如何从 customer_products 表中获取数据?

//Product table
    public function customers()
    {
        return $this->belongsToMany('Customer', 'customer_products')->withPivot('different_price');
    }

    //Customer table
    public function products()
    {
        return $this->belongsToMany('Product', 'customer_products')->withPivot('different_price');
    }

标签: phplaravel-4eloquent

解决方案


推荐阅读