如何在laravel热切帖子中使用列

时间:2018-05-22 19:26:22

标签: laravel laravel-5 eloquent eager

如何在laravel eager帖子中使用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();

请帮忙......

0 个答案:

没有答案