无法 json_encode() 数组或 Laravel 集合:“不支持类型"
问题描述
我不知道我做错了什么,因为它适用于应用程序中的所有其他模型.我多次刷新并重新播种数据库.这些模型扩展了相同的抽象方法.
I don't know what I'm doing wrong since it works with all the other models in the app. I refreshed and reseeded the database multiple times. The models extend the same abstract methods.
这是控制器中的代码:
这是 dd() 输出:
This is the dd() output:
当我使用 JSON_PARTIAL_OUTPUT_ON_ERROR 时,我得到一个 json 字符串.
When I use JSON_PARTIAL_OUTPUT_ON_ERROR I get a json string.
推荐答案
错误的原因是你在 pic
中存储了一个 stream 资源无法序列化为 JSON 的序列化对象的字段.
The reason for the error is the fact, that you're storing a stream resource in pic
field of the serialised object that can't be serialised to JSON.
您可以通过在模型中设置 $hidden
属性来告诉 Eloquent 模型在将所选属性转换为数组时跳过它们:
You can tell Eloquent model to skip selected attributes when they're converted to an array by setting a $hidden
attribute in your model:
这篇关于无法 json_encode() 数组或 Laravel 集合:“不支持类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!