Laravel多对多如何在eloquent或查询生成器中形成查询

时间:2017-10-07 13:51:57

标签: mysql laravel laravel-eloquent laravel-query-builder laravel-5.5

从以下查询获得预期结果:

com.google.firebase.firestore.FirebaseFirestoreException: Failed to get document because the client is offline.

如何在(Eloquent或在查询生成器中)以laravel方式进行查询

注意: 涉及以下表格:


ID

命名

设施
ID
名称

amenities_room
ROOM_ID
amenities_id

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

您收到此错误mb_strpos() expects parameter 1 to be string, object given,因为您的雄辩期待一个字符串,但您已在withCount()传递了一个对象,请尝试此

$rooms = Room::with('amenities')
->withCount('amenities')->where(function($query){
  $query->whereIn('id', [2, 3]);
})
->where('amenities_count', 2)
->get()