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

214
Vistas
how to pass data coming from laravel query as a json object to the function in javascript

i am actually using graphs in my project for which i am passing dynamic data from controller to blade and then in the js script. The js function in the blade accept the array of objects and i dont know how to assign the data from the controller to that js function.

$data['typesBasedProperties'] = DB::table('properties')
            ->join('property_types', 'properties.property_type', 'property_types.id')
            ->select('property_types.types as label', DB::Raw('COUNT(properties.id) as value'))
            ->whereIn('properties.id', $property_ids)
            ->groupBy('label')
            ->get()
            ->toJson();

and this is the js function

var donutChart = function(){
            Morris.Donut({
                element: 'morris_donught',
                data: [
                    {
                    label: " Download Sales ",
                    value: 12,
                    }, {
                    label: " In-Store Sales ",
                    value: 30
                    }, {
                    label: " Mail-Order Sales ",
                    value: 20
                    }
                ],
                resize: true,
                redraw: true,
                colors: ['#2b98d6', 'rgb(59, 76, 184)', '#37d159'],
                //responsive:true,
                
            });
        }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you need to do something like this:

<script>
     var typesBasedProperties = {!! $typesBasedProperties !!}
</script>

After this you have typesBasedProperties object available in all your js code.

Check out laravel documentation for more info.

about 4 years ago · Juan Pablo Isaza 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