Edit not working

I am going through a tutorial and have watched the same video a few times to see if I had incorrect syntax on my form, but to me it looked ok. But when I hit 'edit' and then click save changes I get an error that the value already exists. This is happening on each of the forms I created.

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Group::make()
                ->schema([
                    Section::make()
                    ->schema([
                        TextInput::make('name')
                            ->required()
                            ->live(onBlur:true)
                            ->unique()
                            ->afterStateUpdated(function(string $operation, $state, Forms\Set $set){
                                    if($operation!=='create'){
                                        return;
                                    }
                                $set('slug', Str::slug($state));

                            })
                   
            ])
            ]);
    }
Solution
Because you have ->unique() validation, you have to provide like ->unique(ignoreRecord: true)
Was this page helpful?