I can select country
and groupBy the result as following with an alias total
:
Data::select('country', DB::raw('count(*) as total'))
->groupBy('country')
->get();
The above code works well.
Here I can select only country
filed, But I need to select aslo name
, positions
field, How can I select multiple field here?
You have to use like below settings and change code.
config/database.php
strict
key inside mysql connection settingsfalse
Use code below like
ModelName::groupBy('country')
->selectRaw('count(*) as total, country, name, positions')
->get()