laravel 方法 Illuminate\View\View::__toString() 不得抛出异常
laravel Method Illuminate\View\View::__toString() must not throw an exception
我的密码是
@foreach($top_15_posts as $status )
{!! view('layouts.app-internal.user_status',[
'status'=>$status,
'user'=>\App\Eloquent\User::find($status->users_id)
]) !!}}
@endforeach
如何克服这个错误?
你可能想看看这个。
Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception
有一个非常简单的解决方案:不要将 View 对象转换为字符串。
不要:echo View::make('..');或 echo view('..');
执行:echo View::make('..')->render();或 echo view('..')->render();
通过转换视图,它自动使用__toString() 方法,不会抛出异常。如果您手动调用 render(),异常会正常处理。
这实际上是一个 PHP 限制,而不是 Laravels。在此处阅读有关此 "feature" 的更多信息:https://bugs.php.net/bug.php?id=53648
------------还有这个----------------
情况 1:尝试打印出数组中的值。
答案 1:尝试打印出数组。你确定这是一个数组?当它是一个对象而不是一个数组时,我得到了这个错误。尝试做一个 print_r 看看你得到了什么。
情况 2:您有这样的关联数组:
我的密码是
@foreach($top_15_posts as $status )
{!! view('layouts.app-internal.user_status',[
'status'=>$status,
'user'=>\App\Eloquent\User::find($status->users_id)
]) !!}}
@endforeach
如何克服这个错误?
你可能想看看这个。 Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception
有一个非常简单的解决方案:不要将 View 对象转换为字符串。
不要:echo View::make('..');或 echo view('..');
执行:echo View::make('..')->render();或 echo view('..')->render();
通过转换视图,它自动使用__toString() 方法,不会抛出异常。如果您手动调用 render(),异常会正常处理。
这实际上是一个 PHP 限制,而不是 Laravels。在此处阅读有关此 "feature" 的更多信息:https://bugs.php.net/bug.php?id=53648
------------还有这个----------------
情况 1:尝试打印出数组中的值。
答案 1:尝试打印出数组。你确定这是一个数组?当它是一个对象而不是一个数组时,我得到了这个错误。尝试做一个 print_r 看看你得到了什么。
情况 2:您有这样的关联数组: