Repository: filamentphp/filament

Issue #2074: Nested repeaters are always saving to the first child record  
Created: 2022-04-01T11:28:21Z
Package
filament/forms
Package Version
v2.10.41
Laravel Version
v9.6.0
Livewire Version
v2.10.4
PHP Version
8.1.3
Bug description
I'm creating a nested relation, framework -> competencies (each -> competencies)
Here are the migrations :
Schema::create('frameworks', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });

Schema::create('competencies', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->foreignIdFor(\App\Models\Framework::class, 'framework_id')
                ->nullable()
                ->constrained()
                ->cascadeOnUpdate()
                ->cascadeOnDelete();
            $table->timestamps();
        });
Schema::table('competencies', function (Blueprint $table) {
            $table->foreignId('parent_id')
                ->nullable()
                ->constrained('competencies')
                ->cascadeOnUpdate()
                ->cascadeOnDelete();
        });
My models are :
class Framework extends Model
{
    public function competencies() : HasMany
    {
        return $this->hasMany(Competency::class);
    }
}

class Competency extends Model
{

    public function children() : HasMany
    {
        return $this->hasMany(Competency::class, 'parent_id');
    }

    public function framework(): BelongsTo
    { 
        return $this->belongsTo(Framework::class);
    }
}
I'm using this form on the FrameworkResource
 public static function form(Form $form): Form
    {
        return $form
            ->columns(1)
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->required()
                    ->maxLength(255),
                
                Forms\Components\HasManyRepeater::make('competencies')
                    ->relationship('competencies')
                    ->label(Str::ucfirst(__('competencies')))
                    ->columns(2)
                    ->defaultItems(0)
                    ->schema([
                        Forms\Components\TextInput::make('name')
                            ->label(Str::ucfirst(__('competency')))
                            ->required()
                            ->columnSpan(1),

                        Forms\Components\HasManyRepeater::make('children')
                            ->relationship('children')
                            ->label(Str::ucfirst(__('sub competencies')))
                            ->columnSpan(1)
                            ->defaultItems(0)
                            ->schema([
                                Forms\Components\TextInput::make('name')
                                    ->label(Str::ucfirst(__('competency')))
                                    ->required(),

                            ]),

                    ]),
            ]);
    }
To check the result I created a ViewFramework page (extending ViewRecord) with this view  :
<x-filament::page :widget-record="$record">
<ul>
    @foreach($record->competencies as $competency)
        <li>
             {{ $competency->name }}
             <ul>
                @foreach($competency->children as $competency)
                    <li>
                        {{ $competency->name }}
                    </li>
                @endforeach
            </ul>
        </li>
    @endforeach
</ul>
</x-filament::page>
I'm not able to explain the behaviour!
Steps to reproduce

  
    
    

    Screen.Recording.2022-04-01.at.13.18.33.mov
    
  

  

  


Relevant log output
No response

Duplicate issue #2114: saveRelationshipsUsing is called multiple times!
Created: 2022-04-08T19:45:18Z
Package
filament/filament
Package Version
v2.10.41
Laravel Version
v9.6.0
Livewire Version
No response
PHP Version
v8.1
Bug description
I have a repeater field with saveRelationshipsUsing method and dehydrated(false).
when submitting the form the saveRelationshipsUsing is called multiple times, specificlly 3 times.
This happens when editing the resource, but when creating a new resource it works fine
here is my repeater field
Repeater::make('variations')
->disableLabel()
->label(__('admin.Variations'))
->dehydrated(false)
->saveRelationshipsUsing(function (Repeater $component, $state) {
dump($state);
})
->schema([
                        Grid::make(3)
                            ->schema(function ($state) {

                                return [

                                    FileUpload::make('image')
                                        ->columnSpan([
                                            'default' => 3,
                                            'lg' => 1
                                        ])
                                        ->image(),

                                    Grid::make(3)
                                        ->columnSpan([
                                            'default' => 3,
                                            'lg' => 2
                                        ])
                                        ->schema([

                                            TextInput::make('price')
                                                ->label(__('admin.Price'))
                                                ->required()
                                                ->numeric()
                                                ->minValue(0),

                                            TextInput::make('discount_price')
                                                ->label(__('admin.Discount Price'))
                                                ->lte('price')
                                                ->numeric()
                                                ->minValue(0),

                                            TextInput::make('quantity')
                                                ->label(__('admin.Quantity'))
                                                ->numeric()
                                                ->minValue(0),

                                        ])

                                ];

                            })

                    ])

Steps to reproduce
No response
Relevant log output
No response

Closing comment (2022-04-24T18:02:49Z): Duplicate of #2074