spatie/laravel-schemaless-attributes

Can't use with arrays of objects

csti opened this issue · 1 comments

csti commented

Hello,

I noticed I was not able to access data from objects in an array stored in a json field configured with the schema-less attribute.

Upon looking into this it seems to be due to the fact that getRawSchemalessAttributes calls the fromJson method which calls json_decode, with the assoc option set to convert objects to arrays.

This makes it so that I cannot iterate through an array and then access the items with object notation (->name), as they were stored, but instead everything comes back as an array.

Additionally however, using the field in this way also renders the eloquent where search capability useless when the top level is an array.

I was wondering what your thoughts are on this usage and if you think there's any harm implementing an option where getRawSchemalessAttributes returns an array of objects.

Thanks.

Feel free to PR this. Be sure to included tests to prove that it works.