laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.62k stars 11.03k forks source link

feat: add string support to contains validation rule #53584

Closed bojmaliev closed 1 day ago

bojmaliev commented 2 days ago

This PR updates the contains validation rule to support strings in addition to arrays.

Example:

$request->validate([
    'input' => 'Hello, {name}',
], [
    'input' => 'required|contains:{name}',
]); // Passes

This simplifies string validation by removing the need for custom regex, making it more intuitive and user-friendly.

Docs PR: https://github.com/laravel/docs/pull/10034

I think validation.php should remain the same

taylorotwell commented 1 day ago

This introduces a bit of inconsistent behavior where strings allow wildcards and arrays don't. I think I'll table this one for now... easiest way to accomplish this would be closure based rules.