dsfasdfsda234234 2018-07-04 10:10
浏览 66
已采纳

Laravel 5 JSON Foreach不起作用

I am trying to get data from from foreach loop, and i am pulling that data from database. When I try to "foreach" it says Invalid argument supplied for foreach()

@php
$extras = json_decode($product->extras);
@endphp

@foreach($extras as $key)

print_r($key);
@endforeach

When i do it on local, it works, but on laravel it won't.

Also, when i write OUTSIDE of foreach

{{$extras[0][0]}}

it works.. any suggestions?

  • 写回答

2条回答 默认 最新

  • dongpan1871 2018-07-05 09:13
    关注

    This was the answer.. no logic but works..

    $extras = json_decode($product->extras);
    if (is_array($extras) || is_object($extras)){
        foreach ($extras as $extra){  
    
        }
    }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?