php - foreach over object array not working properly -


I am using charts, JS by DWX (click to find documentation link) I also use Laravel Framework I want to generate some JQuery on the server side to output the graph I want $ json_micromarket_participants passing a the object's range (database query Rows from) that are json_encoded in my controller Each object has Home_name and Average_Occupancy property.

For some reasons my project loop does not work, i get the following error:

  foreach ()   

Invalid argument for my question is two times: 1. Why does not this work? 2. Will this code work in any way to generate names and values ​​in jquery?

Code:

  @section ('content') & lt; Script type = "text / javascript" & gt; Var chart datasource = {{$ json_micromarket_participants}}; $ {Function () {$ ("# chartContainer") dxChart ({Data Source: ChartDataSource, commonSeriesSettings: {argumentField: 'Home_name'}, series: [@foreach ($ json_micromarket_participants as $ micromarket_participant) {name: {{$ micromarket_participant- & gt; Home_name}} ', valueField:' {{$ micromarket_participant- & gt; Average_Occupancy}} '}, @endforeach]})}}) & lt; / Script & gt; & Lt; Div id = "chartcontainer" style = "max-width: 700px; height: 300px;" & Gt; & Lt; / Div & gt; @stop   

In the controller, here's how $ json_micromarket_participants are set up, I think that's fine ...

  $ Micromarket_participants = DB :: table ('home') - & gt; Select (array ('*', db :: raw ('' .QQ) ('' .exe. '' - `Eastx`, 2) + Pau ('Northings.' 'Northings, 2) AS distance') )) - & gt; Having ('distance', '& lt;', $ micromarket_size) - & gt; get(); $ Json_micromarket_participants = json_encode ($ micromarket_participants);    

After

This is not working because you have encoded $ micromarket_participants in json, it's a Create a string, not an array.

I think $ micromarket_participants, in this case, is the category of the object, so you should use this with just keeping in mind:

 < code> @foreach ($ micromarket_participants $ as Micromarket_participant)    

Comments

Post a Comment

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -