Save repeater field in Global Tailor model

How can i save repeater field data to Tailor Global?

The code below does not work…

$post = EntryRecord::inSection('Catalog\Order');

$post->title = 'Test';
$post->status = 'New';
$post->items = ['title' => 'Test', 'price' => '100']; // repeater field

Hi @amristar

This code should work. The items need to be managed as individual models and after the parent model is created

$post = EntryRecord::inSection('Catalog\Order');
$post->title = 'Test 2';
$post->status = 'New';

$post->items()->create(['title' => 'Test', 'price' => '100']);
1 Like

Hey @daft.

So i found this but I’m getting an error now that is as follows:

Add [title] to fillable property to allow mass assignment on [Tailor\Models\RepeaterItem].

How would I get around this?

This should do the trick:

! Don't use this

$post = EntryRecord::inSection('Catalog\Order');
$post->title = 'Test 2';
$post->status = 'New';

$item = new Tailor\Models\RepeaterItem;
$item->title = 'Test';
$item->price = 100;

1 Like

Hmm, that throws an error for me as well:

October\Rain\Element\ElementBase::useConfig(): Argument #1 ($config) must be of type array, null given

But this worked for me like a charm:

    $fees = $booking->fees()->create();
    $fees->title = 'this';
    $fees->price = 25;
1 Like

I will say, I already have the id and look it up like this:

$booking = EntryRecord::inSection('Bookings\Bookings')->find(139);

This is mentioned in the docs, so we’ll need to check it.

Alright, a patch has been added in v3.3.9 for this.

All fields defined by tailor are fillable by default, in addition to the “title” field. Fields should be set to guarded: true to guard them.

There is also a workaround you can use to bypass the exception:

// ... code here ...
// eg: $post->items()->create(['title' => 'Test', 'price' => '100']);