Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Laravel / eloquent and highmaps - data format

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Solved it by removing json_encode PHP function in my JS variable setting/

var subsByCtry = {!! $subsByCtry !!};
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!