2013-05-31 59 views
0

當我使用whereIn的二維數組時,我得到了一個數組到字符串的轉換異常。哪裏用2D陣列?

有可能使用whereIn與像codeigniter 2d數組?

編輯:

,我有一個第二個問題。 當我使用數組中的whereIn時,我沒有得到任何結果。 但是當我在phpmyadmin中使用查詢時,我得到了一個結果。

Array ([0] => Array ([query] => select * from `tab_articles` inner join `tab_categories` on `tab_categories`.`category_id` = `tab_articles`.`category_id` where `article_id` in (?) [bindings] => Array ([article_id] => 4) [time] => 0.79)) 

該數組不爲空。該ID存在於數據庫中,並使用get()來獲得結果,但數組中沒有任何內容。真奇怪。

+0

請考慮將第二個問題轉到第二個問題。當您編輯其他問題時,您會使現有答案無效,並使現在不得不應對這兩個答案的答案者變得更加困難。 –

+0

對不起,下次我會這樣做,因爲我找到了我的第二個問題的解決方案,並在我的第一天和問題在stackoverflow。 – Marco

回答

1

我不這麼認爲。

但是,如果你的數組是一個Eloquent集合,你可以使用modelKeys函數。

$query->whereIn($collection->modelKeys()); 

該函數返回模型主鍵的數組。

https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Eloquent/Collection.php#L92

+0

好吧,我發現了錯誤... 我做了這樣的事情:$ array = array('id'=> $ id),但這不起作用。 解決方案是一個數組,只有ID,沒有任何鍵。 – Marco