Php 从桥接表laravel检索数据

Php 从桥接表laravel检索数据,php,laravel,laravel-5.3,Php,Laravel,Laravel 5.3,我在从“配料配方”表中检索“部分”数据时遇到问题。是否有任何方法可以在不使用查询生成器的情况下获取“部分”数据?这是我在配方模型中检索成分的代码。问题是我想从配方模型中检索部分值 class Recipe extends Model { public function ingredients(){ return $this->belongsToMany('App\Ingredient'); } } 在关系中添加透视表列 public function ingred

我在从“配料配方”表中检索“部分”数据时遇到问题。是否有任何方法可以在不使用查询生成器的情况下获取“部分”数据?这是我在配方模型中检索成分的代码。问题是我想从配方模型中检索部分值

class Recipe extends Model
{
  public function ingredients(){
        return $this->belongsToMany('App\Ingredient');
  }
}

在关系中添加透视表列

public function ingredients()
{
    return $this->belongsToMany('App\Ingredient')->withPivot('portion');
}
然后像这样访问它

$recipe = Recipe::find(1);

foreach ($recipe->ingredients as $ingredient) {
    echo $ingredient->pivot->portion;
}

在关系中添加透视表列

public function ingredients()
{
    return $this->belongsToMany('App\Ingredient')->withPivot('portion');
}
然后像这样访问它

$recipe = Recipe::find(1);

foreach ($recipe->ingredients as $ingredient) {
    echo $ingredient->pivot->portion;
}