Reputation: 11
I have a problem to loop GET data from URL. My array looks like after var dump :
array(5) {
[0]=>
array(5) {
["sku"]=>
string(9) "AH1172164"
["name"]=>
string(21) "dasdas"
["url"]=>
string(42) "21321312"
["price"]=>
string(6) "866.00"
["stocks"]=>
array(1) {
[0]=>
array(3) {
["partner"]=>
string(6) "321312"
["qty"]=>
string(1) "1"
["spotted"]=>
string(14) "1 month "
}
}
}
My code for looping the data in blade file:
@php
$d=$_GET['Api'];
var_dump($d);
foreach($d as $value)
{
echo $value;
}
@endphp
When I use var_dump
the data are listed correctly but when I want to loop the variable $d
I got this error:
Method Illuminate\View\View::__toString() must not throw an exception, caught Facade\Ignition\Exceptions\ViewException: Array to string conversion (View: F:\xampp\htdocs\semafor-master\resources\views\platform\tools\
I have API.. and my controller for this :
public function gen(Request $request)
{
// Some queries, and loops to fill $data variable..
return \Redirect::route('platform.tools.gen', ['Api'=>$data]);
}
I can't use return view, I must use return redirect because after API REQUEST I want to redirect to this route. The gen view is Orchid admin panel screen. What can be the problem?
Thanks in advance.
Upvotes: 0
Views: 960
Reputation: 13289
Looks like you have an array of array variable, so you should encode your value to a string before printing it:
@php
$d=$_GET['Api'];
foreach($d as $value)
{
echo json_encode($value);
}
@endphp
Upvotes: 0
Reputation: 2789
Part of the answer is that somewhere in the stack, there's a call to a magic __toString()
method. Exceptions being called therein is only allowable in Php 7.4 and up. Try wrapping your behavior in a generic try/catch and make it dump the message from the Exception that it's trying to throw. The message you're seeing now is just a symptom of a different problem.
Upvotes: 1