我的代码是
@foreach($top_15_posts as $status ) {!! view('layouts.app-internal.user_status',[ 'status'=>$status, 'user'=>\App\Eloquent\User::find($status->users_id) ]) !!}} @endforeach如何克服这个错误?
my code is
@foreach($top_15_posts as $status ) {!! view('layouts.app-internal.user_status',[ 'status'=>$status, 'user'=>\App\Eloquent\User::find($status->users_id) ]) !!}} @endforeachHow to overcome this error?
最满意答案
你可能想看看这个。 Laravel错误:方法Illuminate \ View \ View :: __ toString()不得抛出异常
有一个非常简单的解决方案:不要将View对象强制转换为字符串。
不要:echo View :: make('..'); 或回声视图('..');
执行:echo View :: make('..') - > render(); 或echo视图('..') - > render();
通过转换视图,它自动使用__toString()方法,不会抛出异常。 如果手动调用render(),则会正常处理异常。
这实际上是PHP限制,而不是Laravels。 在此处阅读有关此“功能”的更多信息: https : //bugs.php.net/bug.php?id = 53648
- - - - - -和这个 - - - - - - - -
情况1:尝试打印出数组中的值。
答案1:尝试打印出阵列。 你确定它是一个阵列吗? 当它是一个对象而不是一个数组时,我得到了这个错误。 尝试做一个print_r,看看你得到了什么。
情况2:你有这样的关联数组,如下所示:
You might want to check this out. Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception
There is a very simple solution: don't cast View object to a string.
Don't: echo View::make('..'); or echo view('..');
Do: echo View::make('..')->render(); or echo view('..')->render();
By casting view, it uses __toString() method automatically, which cannot throw an exception. If you call render() manually, exceptions are handled normally.
This actually is a PHP limitation, not Laravels. Read more about this "feature" here: https://bugs.php.net/bug.php?id=53648
-----------AND THIS---------------
Situation 1: Trying to print out a value in an array.
Answer 1: Try printing out the array. Are you sure it's an array? I've gotten this error when it was an object instead of an array. Try doing a print_r and seeing what you get.
Situation 2: You have this associated array like this:
更多推荐
发布评论