I have the following php / eloquent code in a controller:
public function dashboard()
{
$subsByCtryArr = Organisation::join('countries_currencies', 'countries_currencies.id', '=', 'organisations.country_id')
->select(DB::raw('DISTINCT LCASE(countries_currencies.country_code) AS ctry, COUNT(organisations.id) AS regs'))
->groupBy('ctry')
->get();
$subsByCtry = $subsByCtryArr->pluck('regs', 'ctry')->toJson();
return view("sim-manager.dashboard", compact('subsByCtry', 'userByCtry'));
}
In my blade, inside a JS segment of code I put:
var subsCtry = {!! json_encode($subsByCtry) !!};
If log subsCtry to the console I get:
{"at":1,"au":10,"br":1,"nz":1}
But I need an array of objects for the Highmaps:
[['at', 1],['au', 10],['br', 1],['nz', 10]]
How do I format the data from the back end to my JS variable?
Solved it by removing json_encode PHP function in my JS variable setting/
var subsByCtry = {!! $subsByCtry !!};