所以我有這段代碼: $collectionOfProducts = \DB::table('products_specif')->whereIn('size',$arrayOfAttributes)->whereIn('color',$arrayOfAttributes)->whereIn('material',$arrayOfAttributes)->get('product_code'); $product_codes = $collectionOfProducts->unique(); dd($product_codes->toArray()); $arrayOfProducts = \DB::table('products')->whereIn('product_code',$product_codes)->get(); return view('pages.products', compact('arrayOfProducts','type'));dd() 響應:array:4 [▼ 0 => {#1252 ▼ +"product_code": "SocksCode" } 4 => {#1257 ?} 9 => {#1262 ?} 13 => {#1266 ?}]我想在我的whereIn語句中使用 $product_codes,但我不能因為開頭的那些數字 (0,4,9,13)。如何將此集合/數組轉換為簡單的“product_code”:“code”數組?
1 回答

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
您可以使用 pluck 方法獲取數組product_code
$product_codes= \DB::table('products_specif')
->whereIn('size',$arrayOfAttributes)
->whereIn('color',$arrayOfAttributes)
->whereIn('material',$arrayOfAttributes)->pluck('product_code')->toArray();
$arrayOfProducts = \DB::table('products')->whereIn('product_code',$product_codes)->get();
- 1 回答
- 0 關注
- 212 瀏覽
添加回答
舉報
0/150
提交
取消