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 ...

Jonas Staudenmeir
  • 24,815
  • 6
  • 63
  • 109
Mohammad
  • 497
  • 3
  • 15

0 Answers0