如何在 laravel 急切的帖子中使用 id?
此代码仅返回第一篇文章。
那总是 1 。
但是在某些 WsStock 中,有 3 或 4 个或 ... 帖子。
$stocks = WsStock::select([
'id',
'industryIndex',
'nameFA',
DB::raw('count(industryIndex) as total'),
DB::raw('GROUP_CONCAT( id SEPARATOR ",") as ids')
])
->with([
'posts' => function ($query) use ($userId) {
/*
is here ids ????
$query->whereIn('stock_id', explode(',', 'ids'));
*/
$query->whereUserId($userId);
$query->where('ppa', '!=', null);
},
'indice' => function ($query) use ($userId) {}
])
->whereHas('posts', function ($query) use ($userId) {
/*
is here ids ????
$query->whereIn('stock_id', explode(',', 'ids'));
*/
$query->whereUserId($userId);
$query->where('ppa', '!=', null);
})
->groupBy('industryIndex')->get();
请帮忙 ...