Level 31
Yes, there is: throw away chat-gpt, take actual documentation and write proper rule: https://laravel.com/docs/12.x/validation#custom-validation-rules
1 like
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?
Yes, there is: throw away chat-gpt, take actual documentation and write proper rule: https://laravel.com/docs/12.x/validation#custom-validation-rules
Please or to participate in this conversation.