我很難過這一個。我可以搜索一個ID數組,但我想搜索相反的內容。我有模型與ID列表作爲「with_ids」屬性,並希望搜索類似於mongo數據庫,其中ID是在該ID數組中。 例如使用Laravel 5.4查詢生成器與數組(json序列化)屬性
db.conversations.find({ with_ids: { $in: [id] } })
如何做到這一點與Laravel和mysql /雄辯?
$conversations = Conversation::with('messages.user')->where('with_ids', $id)->orWhere('created_by', $id)->get();
這是哪裏('with_ids',$ id)我無法弄清楚......任何建議?
爲了進一步闡明: 我需要找到用戶是否參與其他對話以及他創建的對話。 with_ids是一個json序列化數組f.ex [1,2,23,12]我如何在數組屬性內搜索?
我認爲你的查詢應該按照它的方式工作。它返回什麼? – EddyTheDove
空白數組...沒有任何對話:: with('messages.user') - > where('with_ids',$ id) - > get(); – IamLasse
哦等等。 'with_ids'在哪裏?在對話或消息中? – EddyTheDove