DEV Community

Discussion on: Validate a local Variable in Laravel Livewire.

Collapse
 
mahdipishguy profile image
Mahdi Pishguy • Edited

You don't need to validate all values by validator for every fields, however this is a simple but i think you can do that for each variable as you want to validate by this code:

public function updated($field)
{
    try {
        $this->validateOnly($field);
    } catch (ValidationException $e) {
        $validator = $e->validator;
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jiteshdhamaniya profile image
Jitesh Dhamaniya

this is when property is public yes. however i wrote post incase you want to validate a local variable which does not have existence on component.

Collapse
 
mahdipishguy profile image
Mahdi Pishguy

oh, i get it now, you are right