Did you check what you have in $itens
?
Not all the possible return values for json_decode are valid for the foreach statement.
From the documentation: https://www.php.net/manual/en/function.json-decode.php#refsect1-function.json-decode-returnvalues
Returns the value encoded in json in appropriate PHP type. Values true, false and null are returned as true, false and null respectively. null is returned if the json cannot be decoded or if the encoded data is deeper than the nesting limit.
celohenryz liked this reply
I typed print_r($itens) and the return was
Array ( [0] => stdClas Object ( [id_produto] => 30 [tamanho] => 1 [quantidade] => 2 [valor_unitario] => 100 ) )
which datatype used in $req->itens_pedido ? please send me output of print_r($req->itens_pedido)
celohenryz liked this reply
return this
[{"id_produto":13,"tamanho":"16/17","quantidade":2,"valor_unitario":180.0}]
try this.
$itens = json_decode($req->itens_pedido);
celohenryz liked this reply
returning the same error ''Invalid argument supplied for foreach()''
please send me the output for the below code
$itens = json_decode($req->itens_pedido); dd($itens);
celohenryz liked this reply
I/flutter (30324): [{id_produto: 13, tamanho: 16/17, quantidade: 1, valor_unitario: 180.0}, {id_produto: 15, tamanho: 4, quantidade: 2, valor_unitario: 200.0}] 2 I/flutter (30324): <script> Sfdump = window.Sfdump (function (doc) { var refStyle = doc.createElement('style'), rxEsc = /([.*+?^${}()|[]/])/g, idRx = /\bsf-dump-\d+-ref[012]\w+\b/, keyHint = 0 <= navigator.platform.toUpperCase().indexOf('MAC') ? 'Cmd' : 'Ctrl', addEventListener = function (e, n, cb) { e.addEventListener(n, cb, false); }; refStyle.innerHTML = 'pre.sf-dump .sf-dump-compact, .sf-dump-str-collapse .sf-dump-str-collapse, .sf-dump-str-expand .sf-dump-str-expand { display: none; }'; (doc.documentElement.firstElementChild doc.documentElement.children[0]).appendChild(refStyle); refStyle = doc.createElement('style'); (doc.documentElement.firstElementChild || doc.documentElement.children[0]).appendChild(refStyle); if (!doc.addEventListener) { addEventListener = function (element, eventName, callback) { element.attachEvent('on' + eventName, function (e) { e.preventDefault = function () {e.returnValue = false;}; e.target = e.srcElement; callback(e); }); }; } function toggle(a, recursive) { var s = a.nextSibling
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community