@vincej You need selectRaw there
->selectRaw('contractors.crew_id, count(*) as members, skill_type.skill, location.location_name, crews.crew_name')
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Ok, so I create a raw SQL join to make certain I have got it right. It works great, here it is:
Select contractors.crew_id, count(*) as members, skill_type.skill, location_name,crew_name
from contractors
join auburntree.crews
on contractors.crew_id=crews.id
join skill_type
on skill_type.skill_id = crews.skill_id
join location
on location.id = crews.location_id
GROUP BY contractors.crew_id;
Now I know it works, I want to apply it to Query Builder. This also works .... to a fashion. In the RAW version I get all the data in the SELECT. However, when I do a dd() of the QB $Data, I get just the contractors.crew_id and nothing else. I don't know what Newb mistake I am making not to get all the same data as the RAW version.
$data = DB::table('contractors')
->join('auburntree.crews', 'contractors.crew_id', '=', 'crews.id' )
->join('auburntree.skill_type', 'contractors.crew_id', '=', 'crews.id')
->join('auburntree.location', 'location.id', '=', 'crews.location_id' )
->select('contractors.crew_id count(*) as members, skill_type.skill, location.location_name, crews.crew_name')
->groupBy('contractors.crew_id')
->get();
dd($data);
The result:
array:6 [▼
0 => {#264 ▼
+"as": "1"
}
1 => {#265 ▶}
2 => {#266 ▶}
3 => {#267 ▶}
4 => {#287 ▶}
5 => {#268 ▶}
]
Sorry for I am sure is a Newb mistake.
Many Thanks !!!
@vincej You need selectRaw there
->selectRaw('contractors.crew_id, count(*) as members, skill_type.skill, location.location_name, crews.crew_name')
Please or to participate in this conversation.