Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anibabbar's avatar

Filament Repeater nested under Repeater Issue.

Hi everyone,

I am creating an ecommerce website where products can have multiple Variations with Attributes and terms.

For Variations I created an repeater field which is storing data in the product_variations table.

In the variations I would like to record different attributes and terms. for this I created a attribute_product_variation table.

  Schema::create('attribute_product_variation', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_variation_id')->constrained()->onDelete('cascade');
            $table->foreignId('attribute_id')->constrained()->onDelete('cascade');
            $table->foreignId('term_id')->constrained()->onDelete('cascade');
            $table->timestamps();
        });

My repeater field is working fine, but nested attribute and terms are not saving in the attribute_product_variation table.

Also the UI is working fine, just not able to store Attributes and terms.

Product Model

  public function variations()
    {
        return $this->hasMany(ProductVariation::class);
    }

ProductVariation Model

  public function product()
    {
        return $this->belongsTo(Product::class);
    }
 public function terms()
    {
        return $this->belongsToMany(Term::class);
    }

    public function attributes()
    {
        return $this->belongsToMany(Attribute::class, 'attribute_product_variation')
                    ->withPivot('term_id')
                    ->withTimestamps();
    }

Attribute Model

   public function terms()
    {
        return $this->hasMany(Term::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }


    public function productVariations()
    {
        return $this->belongsToMany(ProductVariation::class, 'attribute_product_variation')
                    ->withPivot('term_id')
                    ->withTimestamps();
    }

Product Resource

0 likes
3 replies
LaryAI's avatar
Level 58

To address the issue of nested attributes and terms not being saved in the attribute_product_variation table, you need to ensure that the nested repeater data is being properly handled and saved. Here’s a step-by-step solution:

  1. Ensure Relationships are Defined Correctly: Make sure your models have the correct relationships defined. From your provided code, it looks like you have set up the relationships correctly.

  2. Update the Product Resource: You need to ensure that the nested repeater data is being saved correctly. This involves handling the saving process in the ProductResource class.

  3. Handle Saving Nested Data: You need to override the saved method in your ProductResource to handle saving the nested attributes and terms.

Here’s how you can do it:

ProductResource

Explanation:

  1. Form Schema:

    • The form schema defines the structure of the form, including the nested repeaters for variations and attributes.
  2. Saved Method:

    • The saved method is overridden to handle the saving of nested attributes and terms.
    • For each variation, it updates or creates the variation record.
    • It then syncs the attributes for each variation, ensuring that the attribute_product_variation table is updated with the correct attribute_id and term_id.

This should ensure that your nested attributes and terms are saved correctly in the attribute_product_variation table.

Please or to participate in this conversation.