2021年1月19日星期二

Custom rule Laravel Livewire

In Laravel Livewire I added a custom youtube video validation rule. It works very well, the problem is that I need it to be nullable and if I add in the validate nullable it gives me an error and I can't find how to solve this problem.

Input:

<input wire:model="video" class="form-control" type="text" placeholder="Url youtube">  

Rule:

 public function passes($attribute, $value)          {              return (bool) preg_match('/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/',$value);          }  

Validate:

'video' => 'nullable', new RuleYoutube,  

Removing nullable works fine, but the field is not required. And with the nullable property I get the following error:

No property found for validation: [0]

Any suggestion? Thank you very much for spending time in my consultation

https://stackoverflow.com/questions/65799142/custom-rule-laravel-livewire January 20, 2021 at 04:37AM

没有评论:

发表评论