Updating an existing statamic entry with new data #4910
-
I have an existing entry in my Pages collection in statamic. I want to add / append a new item to that exisiting entry in "add_videos" array under block of type "video_block" as highlighted in the screenshot from my core Laravel So far my code looks like this I fetched the exiting entry
this is the new video set I would like to add / append to the existing one
Now the only problem is I am not able to add the new data to that 'video_block' instead it gets added outside at the root level using this
is there a way where I can get hold of that data item and append a new item to it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The field you need to modify is the top level You'll need to get the value of that, modify it, and then re-set it. $blocks = $entry->get('blocks');
// I don't know how you're picking which block to update.
// If it's just the first "video_block" block, then this will do it.
$index = collect($blocks)->search(function ($block) {
return $block['type'] === 'video_block';
});
$blocks[$index]['add_videos'][] = ['title' => 'Entry from Laravel Test Rohan'];
$entry->set('blocks', $blocks);
$entry->save(); |
Beta Was this translation helpful? Give feedback.
The field you need to modify is the top level
blocks
.You'll need to get the value of that, modify it, and then re-set it.