How do I use join with Eloquent taking in consideration the following table structure:
I have a properies table
---------------------
ID | Name
-
This is more of a MySQL join+group+select trick which includes following steps.
join if you want to exclude rows with RoomsCount=0, else use leftJoin)groupBy by primaryKey to avoid duplicates of the join.count of joined table $this->model->leftJoin('Rooms', 'Properties.ID', '=', 'Rooms.Property')
->selectRaw('Properties.*, count(Rooms.RoomID) as RoomsCount')
->groupBy('Properties.ID')
->get();