Migrating to flexible fields with images
merijnponzo opened this issue · 2 comments
I am trying to migrate content into flexible content with spaties media library
I first checked how the structure of my flexible field looks like whenever uploading an image:
Json in my table column 'content'
[{
"key": "cYoFTE5H9jLBxZx1",
"layout": "largevisual",
"attributes": {
"media": [
{
"key": "cPVsiltAD2JZ8Xci",
"layout": "medialayout",
"attributes": {
"link": null,
"title": null
}
}
]
}
}]
So after the migration it looks 1:1 similar (except for the key, this will be different with every image)
[{
"key": "8yb8wIFW0QCzhF8K",
"layout": "largevisual",
"attributes": {
"media": {
"key": "cOhwRSY5LrTK06mp",
"layout": "medialayout",
"attributes": {
"link": null,
"title": null
}
}
}
}]
I created key with Str helper like "cOhwRSY5LrTK06mp" and added them to my spatie image so the key of my related image is the same.
![Screenshot 2023-07-04 at 11 44 43](https://private-user-images.githubusercontent.com/23075300/250845543-ad2d97a0-4f84-4d81-93e3-850a4b822b8f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTMwMzI5OTAsIm5iZiI6MTcxMzAzMjY5MCwicGF0aCI6Ii8yMzA3NTMwMC8yNTA4NDU1NDMtYWQyZDk3YTAtNGY4NC00ZDgxLTkzZTMtODUwYTRiODIyYjhmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEzVDE4MjQ1MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThjYWY2ZWRkNzJmMWYyNTQ2Yzk1Zjg1YjlhNzc5NTM0ZDU4MTExNzAyZTNjZDZiMmZhNWJlNzRhNjZiMGVjMTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.I3KTs_GYOMAWIYdfYaye8cKdyl6QZ65U-2fGTpm8mWc)
However, after the migration i can see all the 'largevisual' blocks, but no images are attached.
And when i press update the media attribute get's empty.
The image key like "cOhwRSY5LrTK06mp" only occurs in my media table and my pages table.
Am i missing something ?
Any help appreciated
I changed my model_type to \Page but it's still not showing up
Okay after hours of debugging it looks likes my structure wasn't 1:1
The images should be stored into an array, while i was migrating one image as an object
if ($image_key) {
//
$randomStringTwo = Str::random(16);
$new_block = [
"key" => $randomStringTwo,
"layout" => "largevisual",
"attributes" => [
"media" => [
[
// add collection key to image
"key" => $image_key,
"layout" => "medialayout",
"attributes" => [
"link" => null,
"title" => null
]
]
],
"title" => null,
"heading" => null
]
];
array_push($new_content, $new_block);
}
now it's working