0
我有一組用戶ID,我嘗試獲取其集合。我一直在使用下面的foreach循環,但是我意識到對於每個循環它都會覆蓋以前的數據。Laravel從ID數組獲取集合
$users = DB::table('user_tags')->where('tag_name', $tag)->whereNotNull('user_id')->lists('user_id');
$users = array_unique($users);
foreach ($users as $key => $value)
{
$users = User::where('id', $value)->get();
}
這怎麼能返回一個集合與所有用戶在該原始數組?
謝謝!
Q - 爲什麼'whereIn'與只是'where'? –
where = id |在哪裏(ID數組) –