How do I use the #[Validate()] attribute in Livewire 3 for unique validation?

35 Views Asked by At

Inside my update() function I have this validation rule that works:

// ...
'email' => [
  'required',
  'email',
  Rule::unique('users')->ignore($this->user),
],
// ...

But I'd like to use the #[Validate()] attribute, since I think its cleaner and more modern. Another reason is that I can create custom messages easily (I'm not a native English speaker, so it is super useful to create custom messages)

Problem is that if I use something like:

#[Validate('unique:users')]
public $email;

It works, but I can't tell it (Or I don't know how) which record to ignore. Is it possible, or for this case its mandatory either to do the validation in a method, or using a rules() function?

0

There are 0 best solutions below