dimanche 20 septembre 2020

Using Validator methods on custom validation rules in AppServiceProvider

This is what my AppServiceProvider's boot method looks like. My custom rule must do this: it must check that the input specified in 0'th parameter does exist and is not null, then must check current attribute's value is and array and is not null;

The problem is, when I try to access $validator's getValue() or validateRequired() methods app gives me an exception like:

Method [getValue] does not exist.

How can I access those methods?

      Validator::extendImplicit('imageArrayWith', function($attribute, $value, $parameters, $validator){
        $imageArray = json_decode($value);
        $requiredRow = $parameters[0];
        $requiredRowVal = $validator->getValue($requiredRow);
        if($validator->validateRequired($requiredWithRow)){
          if(is_array($imageArray)){
            if(count($imageArray) == 0){
              return false;
            }
          }
          return true;
        }else{
          return false;
        }
      });


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2RLCfNC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire