dimanche 4 décembre 2016

Laravel selectRaw with joined table data

I am using the following to sum a total column:

$hive_count = Hive::where('active','true')->groupBy('hive_type_id')->selectRaw('sum(total) as sum, hive_type_id')->pluck('sum','hive_type_id');

But rather than using the hive_type_id for the array key, I would like to access the hive_type name from the hive_types table (column 'name'). I have tried hive_type_id.name but this did not work.

Thanks for your help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire