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

146
Views
Laravel / eloquent y highmaps - formato de datos

Tengo el siguiente código php/eloquent en un controlador:

 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')); }

En mi blade , dentro de un segmento de código JS puse:

 var subsCtry = {!! json_encode($subsByCtry) !!};

Si registro subsCtry a la consola obtengo:

 {"at":1,"au":10,"br":1,"nz":1}

Pero necesito una serie de objetos para Highmaps :

 [['at', 1],['au', 10],['br', 1],['nz', 10]]

¿Cómo formateo los datos desde el back-end a mi variable JS ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Lo resolvió eliminando la función PHP json_encode en mi configuración de variable JS/

 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!