Laravel雄辩的多对多查询where [英] Laravel Eloquent Many-to-Many query whereIn
问题描述
在我的应用程序中,我已将关系从one-to-many
更新为many-to-many
,并且我试图找到一种方法来保持关联的功能.
In my application I have updated a relationship from one-to-many
to many-to-many
and I'm trying to figure out a way to persist associated functionality.
假设我有两个相关的表格,例如狗和主人.如果我有很多主人,并且试图获取这些主人的狗证的清单,我该如何雄辩地做到这一点?
Let's say I have two related tables, e.g. dogs and owners. If I have an array of owners and I'm trying to get a list of dogs id's for those owners, how should I do it eloquently?
在这里问了类似的问题: https://laracasts.com/discuss/channels/laravel/gettingmany-to-many-related-data-for-an-array-elements
Similar question was asked here: https://laracasts.com/discuss/channels/laravel/getting-many-to-many-related-data-for-an-array-of-elements
那么,我怎么得到Owner
在数组中的Dog
模型?
So, How would I get the Dog
models where Owner
is in an array ?
与$associatedDogs = Dog::whereIn('owner_id',$ListOfOwners)->get();
相同的是用于One-To-Many
关系,但适用于Many-to-Many
.
Same thing as $associatedDogs = Dog::whereIn('owner_id',$ListOfOwners)->get();
is for a One-To-Many
relationship, but for Many-to-Many
.
推荐答案
使用 查看全文