在查询构建器中传递集合的元素
Passing an element of a collection in the query builder
我想用在上一个请求中获得的 id 进行第二次请求。
我有 3 个 table:
- 组织
- 用户
- follow_organization(关系table)
我想通过传递之前获取的组织id来获取follow_organization
table中出现的次数
$organization = DB::table('organizations')->where('name', $name)->first();
$followers = DB::table('follow_organizations')->where('organization_id', $organization)->count();
不幸的是,我收到以下错误消息:
Object of class stdClass
could not be converted to string.
我明白了这个问题,我在查询生成器等待字符串时传递了 table。
但是尽管我在互联网上阅读了大量答案,但我还是找不到解决这个问题的方法。
目前您正在将整个组织对象传递到 where 子句中,但您只需要 id
.
要访问 id
属性,您可以使用 $organization->id
DB::table('follow_organizations')->where('organization_id', $organization->id)->count();
我想用在上一个请求中获得的 id 进行第二次请求。
我有 3 个 table:
- 组织
- 用户
- follow_organization(关系table)
我想通过传递之前获取的组织id来获取follow_organization
table中出现的次数
$organization = DB::table('organizations')->where('name', $name)->first();
$followers = DB::table('follow_organizations')->where('organization_id', $organization)->count();
不幸的是,我收到以下错误消息:
Object of class
stdClass
could not be converted to string.
我明白了这个问题,我在查询生成器等待字符串时传递了 table。 但是尽管我在互联网上阅读了大量答案,但我还是找不到解决这个问题的方法。
目前您正在将整个组织对象传递到 where 子句中,但您只需要 id
.
要访问 id
属性,您可以使用 $organization->id
DB::table('follow_organizations')->where('organization_id', $organization->id)->count();