Laravel Eloquent to join table and count related

前端 未结 2 1975
遇见更好的自我
遇见更好的自我 2020-12-06 12:06

How do I use join with Eloquent taking in consideration the following table structure:

I have a properies table

---------------------
ID    | Name 
-         


        
2条回答
  •  粉色の甜心
    2020-12-06 12:24

    Define the relationship on your Property model class:

    hasMany(Room::class);
      }
    }
    
    
    $properties = Property::withCount(['rooms'])->get();
    

    This will add a rooms_count to the result.

提交回复
热议问题