Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Greeenone's avatar

Issue with array stored in DB

Hello everyone,

I'm working on one of my projects and I have a small issue.

I created custom field for tags. Tags are stored in array (Vue component) but when I'm saving my array to database, Nova change format and once I retrieve data from DB, I get array with one element who is my array in string format like: '[tag, tag2, tag3]'

In vue I have: ['tag 1', 'tag3', 'tag3', ]

After that, I serialize in model and in my database I get this: a:1:{i:0;s:14:"tag1,tag2,tag3";}

I tried also to use Json.Parse and Stringify but is not working

Someone know what I'm doing wrong and can help me?

0 likes
2 replies
devingray_'s avatar

Are you casting to array on the model?

protected $casts = [
  'tags' => 'array',
]
Greeenone's avatar

Hello, thanks for reply! I already fixed my issue, and yes, I used casting to array but didn't worked for my. My solution (I don't really know if it's correct):

  • Adding values to array in Vue
  • Stringify array
  • Nova decode json using json_decode
  • Serialize data

Please or to participate in this conversation.