Support the ongoing development of Laravel.io →
posted 8 years ago
Views
Last updated 2 years ago.
0

on the template $chart is an array..

in blade you can echo string only and blade will run htmlentities on every variable it's passed.

you can however do this on the template

<p class="chart">{{ json_encode($chart) }}</p>
Last updated 8 years ago.
0

You are producing an array, arrays are accessed via [], not via ->. So either you return an object from your calculateResult() method (e.g. with stdClass) or you simply use

{{ $chart['x'] }}

As far as I can see this has nothing to do with json whatsoever.

0

ftiersch said:

You are producing an array, arrays are accessed via [], not via ->. So either you return an object from your calculateResult() method (e.g. with stdClass) or you simply use

{{ $chart['x'] }}

As far as I can see this has nothing to do with json whatsoever.

After writing php for well over a decade i should of got that. Thanks ftiersch, now it makes sense. I'd based above on an eleoquent solution but wanted to run calcultions and render results. I'll convert my calculateResults class to return the data as an object.

In the end i just cast the array to an object in the Models return statement ie

return (object) $chart;
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.