簡體   English   中英

Laravel在哪里有麻煩

[英]Have some troubles with Laravel whereIn

因此,我正在嘗試執行:

$table = 'russian_names';
$nameType = 1;
$options = array(1, 2, 6);
$names = DB::table($table)
            ->where('name_type', $nameType)
            ->whereIn('options', $options)
            ->get();

當然,我在russian_names有一排:

id: 1
name: Vito
name_type: 1
options: 1,2,3,6
short_description: Short description for Vito.
description: Full description for Vito.

但是我總是得到一個空數組。 我試圖將$options每個元素轉換為字符串,但仍然沒有結果。 另外,我嘗試不使用whereIn來執行此查詢,並且它可以正常工作。 而且,當我離職時

select * from `russian_names` where `name_type` = 1 and `options` in (1, 2, 6)

在phpmyadmin中,它可以完美運行。 我有什么想念的嗎?

UPD :mysql查詢日志顯示此日志:

select * from `russian_names` where `name_type` = ? and `options` in (?, ?, ?)

看起來很正常,因為

select * from `russian_names` where `name_type` = ?

工作正常,並向我展示結果數組。

選項:1、2、3、6

WHERE options IN (1, 2, 6)是指“找到具有一個行options的值12 ,或6 。這並不意味着”奇跡般地弄清楚, options是一個CSV串並充當如果它是數據的陣列“。您需要以其他方式存儲options -最有可能的是多對多關系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM