-
Notifications
You must be signed in to change notification settings - Fork 917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Table field doesn't work with objects #3642
Comments
@MeerKatDev cast your json field to Let me know if it solves for you, |
I tried both, none works. they give errors either way. What string representation is expected for |
Can't you convert your json to array to display ? also try with https://backpackforlaravel.com/docs/4.1/crud-fields#table-1 states if your work with JSON from database, cast to object or array in model. Maybe the JSON you store is not valid ? This is what my table saves in database: [
{
"desc": "sfdg",
"name": "sdfg"
},
{
"desc": "sfdg",
"name": "sfdg"
}
] Best, |
I thought it was clear above, but I will write it more explicitly: this is the json object I'm using: { "prop1": "val1", "prop2":"val2", ... } which is a proper json object. This what you describe [
{
"desc": "sfdg",
"name": "sdfg"
},
{
"desc": "sfdg",
"name": "sfdg"
}
] is an array of json objects, and it's obviously not what I have an issue with. In the field |
Hello @MeerKatDev I just tried casting to object: public $casts = [
'features' => 'object',`
]; And it works as expected, What I am missing ? Best, |
Could you show me what kind of data |
CRUD::addField([ // Table
'name' => 'features',
'label' => 'Features',
'type' => 'table',
'entity_singular' => 'feature', // used on the "Add X" button
'columns' => [
'name' => 'Feature',
'desc' => 'Value',
],
'max' => 25, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => 'Texts',
]); The saving of this table gives the string I showed you before when casted to object. |
Again, you are still describing an array of JSON objects here, not a JSON object. As the JSON specification says, the difference is:
The casting that you are describing works because Laravel casts an So it's unclear to me why in the docs it says that it supports JSON in general. It doesn't. It supports only arrays. |
Indeed you are right. For reference here it what it says in docs:
It should be:
I think there is room to improve here, this field is quite old, and at the time If you plan to work on this let us know, I think it would be a good addition to suport both |
I created a custom field that deals with any JSON object, should I make a PR? The issue is that it's a quick modification of the |
About the docs: I think it should be very clear that it deals only with array values. From
to
and
and I would leave |
Thanks @MeerKatDev I'v just submited: Laravel-Backpack/docs#247 to clear the docs a bit. If you are willing to send a PR, please do it. If we can make table work with different types of data, or create a custom field, let's discuss there in the PR about the best approach. I am going to close this for now. Wish you the best, |
Bug report
In the docs it's written that
table
works with objects, which I would think it means that it works with json objects like{ 'a':'a', 'b':'b', ...}
, instead it seems to be not usable for that.What I did
I tried to show a JSON object with the
table
field.What I expected to happen
For the object fields to show on different rows, like for the array case
What happened
htmlspecialchars error
What I've already tried to fix it
I'm building a custom field that works with objects
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:The text was updated successfully, but these errors were encountered: