Custom property in CreateRecord form

Hello everyone, Currently, Filament doesn't provide built-in support for the belongsToMany relation in my specific case. Consequently, I've had to resort to using a custom property and managing the creation/editing process manually. What's peculiar is that this approach works seamlessly in the EditRecord context, but encounters an issue in CreateRecord. Upon submitting the form during record creation, the console reports the following error:
Livewire Entangle Error: Livewire property ['data.attributes.10'] cannot be found on component: ['app.filament.resources...']
Livewire Entangle Error: Livewire property ['data.attributes.10'] cannot be found on component: ['app.filament.resources...']
Here's a snippet from my resource form code:
Section::make(__('Attributes'))
->schema([
Grid::make(3)
->schema(function (Get $get): array {
$schema = [];

$attributes = CategoryAttribute::query()
->where('category_id', $get('category_id'))
->with('options')
->select('id', 'name')
->get();

foreach ($attributes as $attribute) {
$schema[] = Select::make("attributes.$attribute->id")
->required()
->label($attribute->name)
->options($attribute->options->pluck('name', 'id'))
->searchable();
}

return $schema;
})
])
->key('attributes'),
Section::make(__('Attributes'))
->schema([
Grid::make(3)
->schema(function (Get $get): array {
$schema = [];

$attributes = CategoryAttribute::query()
->where('category_id', $get('category_id'))
->with('options')
->select('id', 'name')
->get();

foreach ($attributes as $attribute) {
$schema[] = Select::make("attributes.$attribute->id")
->required()
->label($attribute->name)
->options($attribute->options->pluck('name', 'id'))
->searchable();
}

return $schema;
})
])
->key('attributes'),
EditRecord code:
protected function mutateFormDataBeforeFill(array $data): array
{
/** @var Product $record */
$record = $this->getRecord();

$attributes = $record->attributes->keyBy('id');

return [
...$data,
'attributes' => $attributes->map(fn ($attribute) => $attribute->pivot->value)->toArray(),
];
}
protected function mutateFormDataBeforeFill(array $data): array
{
/** @var Product $record */
$record = $this->getRecord();

$attributes = $record->attributes->keyBy('id');

return [
...$data,
'attributes' => $attributes->map(fn ($attribute) => $attribute->pivot->value)->toArray(),
];
}
1 Reply
ngoquocdat
ngoquocdatOP14mo ago
anyone squint
Want results from more Discord servers?
Add your server