laravel方法Illuminate \ View \ View ::

编程入门 行业动态 更新时间:2024-10-25 16:23:07
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

如何克服这个错误?

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) ]) !!}} @endforeach

How 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:

更多推荐

本文发布于:2023-08-01 02:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351433.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   laravel   View   Illuminate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!