filament/filament
v3.2
v11.9
v3.5
PHP 8.3
Following the example of using a repeater to fill BelongsToMany relationships [https://filamentphp.com/docs/3.x/forms/fields/repeater], I want to nest two repeaters with BelongsToMany relationships to handle a scenario like this:
I have Orders that have Products, which in turn have Colors.
I'm encountering a bug during the initial save: the color is not saved correctly because the order_product_id column in the color_order_product table is null. However, if I add new colors to a product in the order afterward, the modification is saved correctly.
But if I add a new product, the same issue arises.
Repeater::make('order_product')
->relationship('orderProducts')
->schema([
Select::make('product_id')
->relationship('product', 'title')
->required()
->live(),
Repeater::make('colorOrderProducts')
->relationship('colorOrderProducts')
->schema([
Select::make('color_id')
->options(
function ($get) {
$selectedProduct = Product::find($get('../../product_id'));
if ($selectedProduct) {
return $selectedProduct->colors()->get()->pluck('title', 'id');
}
}
)
->required(),
])
])
When creating an order, adding products, and assigning colors to those products using the nested repeater, all entries should be saved correctly.
Create an order with products and assign colors to those products using the nested repeater.
Save the order.
Check the color_order_product table and observe that the order_product_id column is null for the initially added colors.
Add new colors to the existing product and save again. Observe that these new colors are saved correctly.
Add a new product to the order and assign colors. Save and observe the issue reoccurs.
https://github.com/marc31/filament-nested-repeater-w-relationship
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too