【问题标题】:laravel Method Illuminate\View\View::__toString() must not throw an exceptionlaravel Method Illuminate\View\View::__toString() 不能抛出异常
【发布时间】:2016-07-13 22:49:54
【问题描述】:

我的代码是

 @foreach($top_15_posts as $status )
       {!!  view('layouts.app-internal.user_status',[
       'status'=>$status,
       'user'=>\App\Eloquent\User::find($status->users_id)
            ]) !!}}
 @endforeach

如何克服这个错误?

【问题讨论】:

标签: php laravel-5.2


【解决方案1】:

您可能想检查一下。 Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception

有一个非常简单的解决方案:不要将 View 对象转换为字符串。

不要:回显 View::make('..');或回显视图('..');

执行:echo View::make('..')->render();或 echo view('..')->render();

通过强制转换视图,它会自动使用 __toString() 方法,不会抛出异常。如果手动调用render(),异常会正常处理。

这实际上是 PHP 的限制,而不是 Laravel。在此处阅读有关此“功能”的更多信息:https://bugs.php.net/bug.php?id=53648

-----------还有这个---------------

情况 1:试图打印出数组中的值。

答案 1:尝试打印出数组。你确定它是一个数组?当它是一个对象而不是数组时,我得到了这个错误。试着做一个 print_r 看看你得到了什么。

情况2:你有这样的关联数组:

【讨论】:

  • 实际上我使用了 echo 和 view 但 phpstorm 显示丢失错误;和)。
  • Render() 帮我搞清楚这个
猜你喜欢
  • 2015-04-14
  • 2014-12-19
  • 2016-09-23
  • 2015-04-04
  • 2014-11-18
  • 2021-08-03
  • 2014-04-20
  • 2014-05-15
  • 1970-01-01
相关资源
最近更新 更多