简体   繁体   English

Laravel 错误:View::__toString() 不得抛出异常

[英]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.

相关问题 Laravel 错误:方法 Illuminate\\View\\View::__toString() 不能抛出异常 - Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception Laravel错误:方法Illuminate \ View \ View :: __ toString()不得抛出异常 - Laravel Error : Method Illuminate\View\View::__toString() must not throw an exception 方法Illuminate \\ View \\ View :: __ toString()不得在Laravel中引发异常 - Method Illuminate\View\View::__toString() must not throw an exception in Laravel Laravel\\Passport\\Bridge\\AccessToken::__toString() 方法一定不能抛出异常,升级后捕捉到 InvalidArgumentException 错误 - Method Laravel\Passport\Bridge\AccessToken::__toString() must not throw an exception, caught InvalidArgumentException error after upgrading 方法 Laravel\\Passport\\Bridge\\AccessToken::__toString() 不能抛出异常 - Method Laravel\\Passport\\Bridge\\AccessToken::__toString() must not throw an exception Laravel / Sentry Eloquent \\ User :: __ toString()不能抛出异常 - Laravel/Sentry Eloquent\User::__toString() must not throw and exception 使用string时,__ toString()不得抛出异常错误 - __toString() must not throw an exception error when using string 方法App \\ Follower :: __ toString()不得引发异常:错误 - Method App\Follower::__toString() must not throw an exception: Error 在 Laravel 中验证时出现致命异常“Method Illuminate\\Validation\\Rules\\RequiredIf::__toString() must not throw an exception” - Fatal exception "Method Illuminate\Validation\Rules\RequiredIf::__toString() must not throw an exception" when validating in laravel Swift_Message :: __ toString()不得引发异常 - Swift_Message::__toString() must not throw an exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM