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

216
Views
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 answers
Answer question

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 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!