Wednesday, March 8, 2017

Using Laravel 5.4 query builder with an array (json serialized) attribute

I'm stumped on this one. I can search an array of ids but I want to search the reverse. I have models with lists of ids as "with_ids" attribute and want to search similar to mongo db where id is in that array of ids. For example

db.conversations.find( { with_ids: { $in: [id] } } )

How do I do that with Laravel and mysql/Eloquent?

$conversations = Conversation::with('messages.user')->where('with_ids', $id)->orWhere('created_by', $id)->get();

it's the where('with_ids', $id) I can't figure out... Any suggestions??



via IamLasse

Advertisement