[英]Laravel error: View::__toString() must not throw an exception
I have a problem to loop GET data from URL.我从 URL 循环获取数据时遇到问题。 My array looks like after var dump:
我的数组在 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:当我使用
var_dump
时,数据被正确列出,但是当我想循环变量$d
时,我得到了这个错误:
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\
Method Illuminate\View\View::__toString() 一定不能抛出异常,捕捉到 Facade\Ignition\Exceptions\ViewException: Array to string conversion (View: F:\xampp\htdocs\semafor-master\resources\views\platform\工具\
I have API.. and my controller for this:我有 API.. 和我的 controller :
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.我不能使用返回视图,我必须使用返回重定向,因为在 API REQUEST 之后我想重定向到这条路线。 The gen view is Orchid admin panel screen.
gen 视图是 Orchid 管理面板屏幕。 What can be the problem?
可能是什么问题?
Thanks in advance.提前致谢。
Part of the answer is that somewhere in the stack, there's a call to a magic __toString()
method.部分答案是堆栈中的某个地方调用了一个神奇的
__toString()
方法。 Exceptions being called therein is only allowable in Php 7.4 and up.只有在 Php 7.4 及更高版本中才允许在其中调用异常。 Try wrapping your behavior in a generic try/catch and make it dump the message from the Exception that it's trying to throw.
尝试将你的行为包装在一个通用的 try/catch 中,并让它从它试图抛出的异常中转储消息。 The message you're seeing now is just a symptom of a different problem.
您现在看到的消息只是另一个问题的症状。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.