Make the field required only on creation.

I have user form with field password. I need to make the form mandatory only if it is in creation state. On updation, the field should be non-mandatory.

TextInput::make('password')
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (Page $livewire) => ($livewire instanceof CreateUser) ? false : true),

This is what I h ave given, please advice me how to make it working.

Thanks
Solution
->required(fn (string $context) => $context === 'create')
This is working for me. Thank you.
Was this page helpful?