Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda