lundi 29 juin 2020

Use a default laravel validation rule inside custom rule file

I want to validate that my input is either UUID or "LAST_QUESTION". I created a custom validation rule LastOrUUID and I would like to use UUID validation rule inside of it. I could not find any way to do that, maybe you know what is the right way to implement this? My custom rule for context:

class LastOrUUID implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {

        if ($value === 'LAST_QUESTION' /* || this is uuid */) {

            return true;

        }

        return false;

    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        // TODO - add translation
        return 'This should either be the last question or have a reference to next question!';
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire