你在Laravel 工作时见过这个可爱的错误吗?

Method Illuminate\View\View::__toString() must not throw an exception

我看过了,非常烦人.我发现了抛出此错误的两个原因.我只是想帮助人们不用花上一小时又一小时的时间.

查看答案&以下情况:)

推荐答案

情况1: try 打印数组中的值.

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.

情景2:

Array
    (
        [post_id] => 65
        [post_text] => Multiple Images!
        [created_at] => 2014-10-23 09:16:46
        [updated_on] => 
        [post_category] => stdClass Object
            (
                [category_label] => Help Wanted
                [category_code] => help_wanted
            )

        [employee_full_name] => Sam Jones
        [employee_pic] => /images/employee-image-placeholder.png
        [employee_email] => jon@gmail.com
        [post_images] => Array
            (
                [0] => stdClass Object
                    (
                        [image_path] => 9452photo_2.JPG
                    )

                [1] => stdClass Object
                    (
                        [image_path] => 8031photo_3.JPG
                    )

            )

    )

当您试图直接在视图中访问post_images数组时,它会抛出一个错误.No. Matter. What. You. Do.

答复2:

I hope this helps someone else. :) I just know the error I kept getting didn't help me anywhere.

Laravel相关问答推荐

在GitHub操作中缺少PHPStan和PHPMD输出,但在本地存在

在Laravel Livewire中,如果一个输入基于另一个唯一的字段是唯一的,如何判断验证?

Laravel 语法 GroupBy 获取列到数组

如何计算具有特定 ID Laravel 的行

无法找到用户sail:passwd 文件中没有匹配的条目

如何通过 Controller 访问 Laravel 中 Model 的值?

mysql 加入 ON 和 AND 到 laravel eloquent

Laravel Eloquent - 随叫随到的加密/解密数据

如何使用 Laravel Passport 在 API 中正确实现 OAuth?

Laravel 5在blade中 echo 包含html的会话变量

用 laravel 表单确认删除?

Laravel whereDoesntHave() - 多个 OR 条件

Laravel 中的合同和 PHP 中的接口有什么区别?

Laravel Electron邮件验证模板位置

将 Laravel Socialite 与 API 一起使用?

调用未定义的方法 Maatwebsite\Excel\Excel::load()

为什么客户凭证应该与 Laravel Passport 中的用户相关联?

Laravel 迁移命名约定

Laravel:在另一个控制器中加载方法而不更改 url

Laravel 删除集合中的第一项