Laravel雄辩的多对多查询where [英] Laravel Eloquent Many-to-Many query whereIn

查看:84
本文介绍了Laravel雄辩的多对多查询where的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我已将关系从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.

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆