Set value for field type #592
-
I'm using schemaless-attributes for my JSON columns, but the fields always want an array. Is there a method in the field API that lets you manipulate the value that's fed to the field? If not, is the recommended way to do this to create a separate attribute cast (i.e. meta_array) on the model, and point the field at that? Semi-related...what if I just want to throw a JSON blob into a text area? |
Beta Was this translation helpful? Give feedback.
Answered by
christmex
Jul 29, 2023
Replies: 1 comment 1 reply
-
In the meantime, I'm using the attribute cast, for anyone facing the same issue with a custom class cast: public function modelMetaArray() : Attribute
{
return Attribute::make(
get: fn($value) => $this->meta->toArray(),
set: fn($value) => ['meta' => $value],
);
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @stephenr85 in my opinion I think I would go the same way as you, it's already a good way.
Backpack PRO also has this field called table to manage the same as your case.