Seeding repeaters
Created 6 years ago by damian_nzHey I am wanting to create some seeds in my theme for repeaters that I reuse. Things like hero image, images with captions etc. As there are tables generated when creating repeaters in the backend I am wondering how I can create the repeaters programmatically to achieve the same result. Thanks 😄
piterden
—
6 years ago
if ($properties = array_get($commandResponse, 'props'))
{
$properties = collect($properties)->mapWithKeys(
function ($prop, $key)
{
return [str_slug($key) => $prop];
}
)->toArray();
$repeater = $this->streams->findBySlugAndNamespace(
$type->getSlug(), 'repeater'
);
$repeaterEntry = $repeater->getEntryModel();
$repeater->setConfigAttribute([
// 'related' => 'Anomaly\Streams\Platform\Model\Repeater\Repeater'.ucfirst($type->getSlug()).'EntryModel',
'related' => class_basename($repeaterEntry),
]);
foreach ($properties as $key => $value)
{
$repeaterEntry->setFieldValue($key, $value);
}
}
ryanthompson
—
6 years ago
Best Answer
Seeding repeaters is a lot like seeding any other stream. Then you sync
the relations on the base entry.
So try and determine the entry model based on naming conventions for the repeater entry model and create a bunch - then sync their IDs to the entry that has the assigned repeater field.
Seeding repeaters is a lot like seeding any other stream. Then you
sync
the relations on the base entry.So try and determine the entry model based on naming conventions for the repeater entry model and create a bunch - then sync their IDs to the entry that has the assigned repeater field.