arctushar
1 year ago

array iteration in blade not working

Posted 1 year ago by arctushar

My code in controller is as below

$obj = [];
foreach($sectors as $sector){
    foreach($sector->codelists as $objindex=>$codelist){            
        $dsedatas=Dsedata::where('codelist_id',$codelist->id)->where('date',$date1)->get(); 
        foreach($dsedatas as $i=>$dsedata){
            $obj[$objindex][$i]=$dsedata;
        }
    }
}
return view('minalysistest')->with('obj',json_encode($obj));

and my code in blade is as below

{{$obj}}
@foreach($obj as $sector)
{{$sector}}
<hr/>
@endforeach

here only $obj is showing but foreach not working.

my {{$obj}} is as below

{"4":{"25":{"id":1611215,"codelist_id":33,"ltp":"11.0","trade":95,"value":"8.487","volume":774080,"date":"2018-08-30","time":"13:54:05","created_at":"2018-08-30 13:54:05","updated_at":"2018-08-30 13:54:05"},"29":{"id":1612445,"codelist_id":33,"ltp":"10.9","trade":128,"value":"12.178","volume":1112495,"date":"2018-08-30","time":"14:08:05","created_at":"2018-08-30 14:08:05","updated_at":"2018-08-30 14:08:05"}},"18":{"51":{"id":1614691,"codelist_id":219,"ltp":"16.9","trade":293,"value":"27.150","volume":1591319,"date":"2018-08-30","time":"14:28:06","created_at":"2018-08-30 14:28:06","updated_at":"2018-08-30 14:28:06"}},"21":{"44":{"id":1609459,"codelist_id":252,"ltp":"25.4","trade":334,"value":"15.521","volume":608059,"date":"2018-08-30","time":"13:30:05","created_at":"2018-08-30 13:30:05","updated_at":"2018-08-30 13:30:05"}},"31":{"63":{"id":1614239,"codelist_id":251,"ltp":"61.4","trade":408,"value":"41.515","volume":675358,"date":"2018-08-30","time":"14:24:06","created_at":"2018-08-30 14:24:06","updated_at":"2018-08-30 14:24:06"}}}

what is the problem ?? what is the solution ?

Please sign in or create an account to participate in this conversation.