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?
This was the answer.. no logic but works..
$extras = json_decode($product->extras);
if (is_array($extras) || is_object($extras)){
foreach ($extras as $extra){
}
}
Return your $extras through the controller
public function index()
{
.......
$extras = $product->extras;
return view('yourView', compact('extras'));
}