Sekiro's avatar

Custom validation rules

I wanted to make custom validation for insults so chatgpt give me this

php artisan make:rule NoProfanity

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class NoProfanity implements Rule { public function passes($attribute, $value): bool { $badWords = ['badword1', 'insult1', 'curseword']; // Customize this list

    foreach ($badWords as $word) {
        if (stripos($value, $word) !== false) {
            return false;
        }
    }

    return true;
}

public function message(): string
{
    return 'The :attribute contains inappropriate language.';
}

}

but it says that 'Illuminate\Contracts\Validation\Rule' is deprecated. is there another option?

0 likes
2 replies

Please or to participate in this conversation.