Can't json_encode() an array or Laravel collection: “Type is not supported”

前端 未结 1 762
别那么骄傲
别那么骄傲 2021-01-22 15:14

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 abstrac

相关标签:
1条回答
  • 2021-01-22 16:00

    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.

    You can tell Eloquent model to skip selected attributes when they're converted to an array by setting a $hidden attribute in your model:

    class Substrate extends Model {
      protected $hidden = ['pic'];
    }
    
    0 讨论(0)
提交回复
热议问题