Laravel 5 在查询生成器中传递集合的元素
我想用上一次请求中获得的id进行第二次请求 我有三张桌子:Laravel 5 在查询生成器中传递集合的元素,laravel-5,eloquent,laravel-query-builder,Laravel 5,Eloquent,Laravel Query Builder,我想用上一次请求中获得的id进行第二次请求 我有三张桌子: 组织机构 使用者 跟踪组织(关系表) 我想通过传递先前获得的组织id来获取follow_organization表中的出现次数 $organization=DB::table('organizations')->where('name',$name)->first(); $followers=DB::table('follow_organizations')->其中('organization_id',$organization)-
- 组织机构
- 使用者
- 跟踪组织(关系表)
follow_organization
表中的出现次数
$organization=DB::table('organizations')->where('name',$name)->first();
$followers=DB::table('follow_organizations')->其中('organization_id',$organization)->count();
很遗憾,我收到以下错误消息:
类stdClass
的对象无法转换为字符串
我理解了这个问题,我在查询生成器等待字符串时传递了一个表。
但是,尽管我在互联网上读到了大量的答案,我还是找不到这个问题的解决方案。目前,您正在将整个组织对象传递到where子句中,但您只需要
id
要访问id
属性,可以使用$organization->id
DB::table('follow_organizations')->where('organization_id',$organization->id)->count();
当前,您正在将整个组织对象传递到where子句中,但您只需要
id
要访问id
属性,可以使用$organization->id
DB::table('follow_organizations')->where('organization_id',$organization->id)->count();
在传递整个对象时,需要将
id
从组织传递到where
子句:DB::table('follow_organizations')->where('organization_id',$organization->id)->count()代码>谢谢@Remul!我没有办法只传递id而不是整个集合!我不能将您的评论放在“solution”中,但这是正确的解决方案您需要在传递整个对象时,将id
从组织传递到where
子句:DB::table('follow_organizations')->where('organization_id',$organization->id)->count()代码>谢谢@Remul!我没有办法只传递id而不是整个集合!我不能把你的评论放在“解决方案”中,但这是正确的解决方案