0

Hi I want to gate 3 models against every brand and I use this code in my controller

 $brand = Brand::with (['models' => function ($q){
            $q->take(3);
    }])->get()->toArray();

But it takes only 3 models for the first brand not for all Here is the image of my dd command SO tell me how to gat 3 models for all brands.

4

1 回答 1

0

使用收集方法图后我找到了一种解决方案,您可以获得所有品牌的 3 种型号

  $feed= Brand::with(['models'])->get()->map(function ($query) {
        $query->setRelation('models', $query->models->take(3));
        return $query;
    });
于 2019-01-18T13:13:38.207 回答