[英]Laravel whereIn doesn't return all data
我有以下數組(由explode方法創建)
["3D Printing"," 3D Architecture"," .NET Micro Framework"]
當我嘗試將此標題與我的數據庫匹配並獲取每個標題的 id 時,我只得到第一個項目的 id。
["d21c6805-8780-4726-ba1d-12c9c3a28d0a"]
它應該返回這樣的東西
["d21c6805-8780-4726-ba1d-12c9c3a28d0a", "1234...", "567...]
code
$a = $request->input('tags');
$b = str_replace(['[',']'], null, $a);
$comingTags = explode(',',$b);
$iddss = Tag::whereIn('title', $comingTags)->pluck('id');
return response()->json($iddss);
有什么建議嗎?
PS:我最好的猜測是我的數組中的第 2 項和第 3 項有空格,這可能會導致問題"{SPACE IS HERE}3D Architecture"
不確定這是否是原因。
我試過$b = str_replace([',', ' '], ['',''], $a);
但我現在得到的只是[]
通過使用$b = str_replace(['[', ']', ' '], null, $a);
它確實從我的字符串中刪除了空格,但也刪除了我的標題單詞之間的空格,因此3D Architecture
變為3DArchitecture
並且我也無法將標題與我的數據庫在$iddss = Tag::whereIn('title', $comingTags)->pluck('id');
因為我的數據庫標題是3D Architecture
而我試圖與之匹配的是3DArchitecture
。
對此有什么建議嗎?
$a = $request->input('tags');
// return
"[3D Printing, 3D Architecture, .NET Micro Framework]"
.
$b = str_replace(['[',']'], null, $a);
// return
"3D Printing, 3D Architecture, .NET Micro Framework"
.
$comingTags = explode(',',$b);
// return
["3D Printing"," 3D Architecture"," .NET Micro Framework"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.