Hello guys,
How can I have a store () and update () rules. The rules will be different for each of the methods.
Thanks!
Hello guys,
How can I have a store () and update () rules. The rules will be different for each of the methods.
Thanks!
In both method you can have $this->validate([
rules separately OR if you have single validation method then you can make difference based on $id
If you provide $this->validate()
in your store
and update
methods with an array of validation rules, Livewire will validate against those rules rather than any rules you define in the $rules
property.
public function store()
{
$this->validate([
'email' => [ 'required', 'email', 'unique:users' ]
]);
}
public function update()
{
$this->validate([
'email' => [ 'required', 'email', 'unique:users,email'.$this->user->id ]
]);
}
There is a lot of information about validation in the official docs.