Crud: Fake fields are double encoded

Created on 19 Feb 2017  路  10Comments  路  Source: Laravel-Backpack/CRUD

When using fake fields I assumed I would also be able to access them by casting them to object or array (as the $casts in the documentation suggests). However when I look at the data returned by my API the data still is a JSON string. When I look at the data in the database, the data appears to be double encoded (ie. a string of a json_encoded object), which breaks the $casts to object/array. Also inside the FakeFields trait, the attribute value is checked for being "is_object", but if you cast to array (per documentation) you should check for is_array (also), otherwise you get an error because json_decode expects a string but gets an array.

Bug urgent

All 10 comments

And another note, I actually used the video element as input for the fake fields, which actually resulted in triple encoded data in the database (this however might not be (easily) fixed)...

Same issue I had here: https://github.com/Laravel-Backpack/CRUD/issues/259

I had to use a setter/getter instead of casting.

HI guys,

Does a composer update fix it for you?
What version of Backpack\CRUD are you using, @chancezeus ?

Cheers!

This seems to still be an issue. It seems like the FakeFields trait is unnecessarily json_encode-ing fake fields. Additionally, CrudTrait is attempting to json_decode arrays, json, and objects. Assuming the goal would be to use the casts property and allow Laravel to do it's thing, seems unnecessary to do these other actions.

I have updated to the latest version.

Hi @a2thek26 - thanks for the feedback. Are you using FakeFields on a multi-language entity, or a single-language one?

Thanks, cheers!

@tabacitu Single language.

The double encoding of fake fields just ruined my whole project, I can't do any eloquent queries on the fake fields...

Not possible:
where('extras->key', 'value')

@fede91it When do you expect a merge?

@fede91it thanks a lot for the PR - it looks great. Let's move the conversation there please.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexanderWM picture AlexanderWM  路  3Comments

deepaksp picture deepaksp  路  3Comments

abewartech picture abewartech  路  3Comments

dividy picture dividy  路  3Comments

alexgmin picture alexgmin  路  3Comments