Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kankai's avatar

query multiple data

Hi all,

I need to return a result with multiple query, here is my code and it only return with '[ ]' symbol.

$tags = DB::table('game_id')->where('status',0)->where('wallet',$player_id)->pluck('game_id');
        
            $data = oldwork::where(function($query) use($tags)
            {
                foreach($tags as $tags)
                {
                    $query->where('game_id', $tags);
                }
            })->get();

            return $data;   

It's there any problem with my code?

0 likes
1 reply
MikeMacDowell's avatar
foreach($tags as $tags)
                {
                    $query->where('game_id', $tags);
                }

Will append each where clause as an AND, so it will only fetch results where ALL of your tags are present.

Either use:

$query->whereIn('game_id', (array)$tags);

or

foreach($tags as $tags)
                {
                   $query->orWhere('game_id', $tags);
                }

Please or to participate in this conversation.