使用带有数组(json序列化)属性的Laravel5.4查询生成器

使用带有数组(json序列化)属性的Laravel5.4查询生成器,laravel,eloquent,laravel-query-builder,Laravel,Eloquent,Laravel Query Builder,我在这件事上被难住了。我可以搜索ID数组,但我想搜索相反的数组。我有一些模型的id列表为“with_ids”属性,并且希望搜索类似于mongo db的id,其中id位于id数组中。 比如说 db.conversations.find( { with_ids: { $in: [id] } } ) 我如何使用Laravel和mysql/Elotent做到这一点 $conversations = Conversation::with('messages.user')->where('with_

我在这件事上被难住了。我可以搜索ID数组,但我想搜索相反的数组。我有一些模型的id列表为“with_ids”属性,并且希望搜索类似于mongo db的id,其中id位于id数组中。 比如说

db.conversations.find( { with_ids: { $in: [id] } } )
我如何使用Laravel和mysql/Elotent做到这一点

$conversations = Conversation::with('messages.user')->where('with_ids', $id)->orWhere('created_by', $id)->get();
这是我不知道的地方('with_id',$id)。。。有什么建议吗

进一步澄清:
我需要找出用户是否参与了其他对话以及他创建的对话。with_id是一个json序列化的数组f.ex[1,2,23,12]如何在数组属性中搜索?

我不太清楚。您是否尝试了
其中的()

编辑

$conversations = Conversation::with('messages.user', function($query) {
    $query->where('id', $id); // user_id ?
})
->orWhere('created_by', $id)
->get();

经过多次挖掘,我终于找到了解决办法。在一个whereRaw查询中查找集合中的。如果有其他人遇到这个问题,希望能有所帮助

这并不漂亮,因为出于某种原因,报价需要删掉

Conversation::where('created_by', $id)->orWhereRaw("FIND_IN_SET(?, REPLACE(REPLACE(REPLACE(with_ids, '\"', ''), '[', ''), ']','')) > 0", $id)->get()

这是最后一个查询,用于获取用户创建或参与的聚合对话。

我需要它,反之亦然。我有一个id,我需要检查它是否存在于id“with_id”列表中,我需要找到用户是否参与了其他对话以及他创建的对话。e、 g.with_ID是用户ID的列表。with_ids是一个json序列化的数组f.ex[1,2,23,12]如何在数组属性中搜索?您是否至少尝试过这一点。请这样做,让我们看看。我认为你的查询应该是这样的。它返回什么?空白数组。。。nothing对话::with('messages.user')->where('with_id',$id)->get();哦,等等。“带_id”在哪里?在对话中还是在信息中?在对话中。它位于由创建的和使用的之间。ID是用户参与的`Conversation::with('messages.user')->get()`返回?与所有相关用户的所有对话?
Conversation::where('created_by', $id)->orWhereRaw("FIND_IN_SET(?, REPLACE(REPLACE(REPLACE(with_ids, '\"', ''), '[', ''), ']','')) > 0", $id)->get()