Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 Respuestas
Responde la pregunta

0

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

var subsByCtry = {!! $subsByCtry !!};
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda