我想将以下代码从集合转换为构建器
return $buyer->transactions()->with('product.pt')
->get()
->pluck('product.pt')
->unique('id')
->values();
然后在返回的构建器上运行->get();
,以获取pt
的集合
我能做的最接近的是return $buyer->transactions()->with('product.pt')
,但是运行->get();
会给我一个transactions
的集合,与pt
有关系
答案 0 :(得分:0)
Pt::whereHas('product', function($query){
$query->whereIn('transaction_id', $buyer->transactions->pluck('id'));
})->get();
如果不清楚,请问一下,但我认为这个例子说明了一切。