0

How can I use ids in laravel eager posts?

This code only returns the first post.

That is always 1 .

But in some WsStock, there are 3 or 4 or ... posts.

$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();

please help ...

3
  • * in code must one result for post. please help , * you question is not clear
    – Shobi
    Commented May 22, 2018 at 20:11
  • question updated
    – Mohammad
    Commented May 22, 2018 at 20:40
  • Please post the WsStock model. Commented Jun 6, 2018 at 21:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.