Skip to content

Conversation

@amaelftah
Copy link
Contributor

Resubmission of #39620 cause it's a breaking change

i found that when using the Rule::where or any where methods they only accept arrays ... while the underlying query builder can accept collections too ... so I have modified the implementation and here is an example of before vs after

before

$names = collect(['foo', 'bar']);
$companiesIds = collect([1, 2]);

$request->validate([
    'first_name' => Rule::in($names),
    
     //here we have to chain ->toArray()
    'company' => Rule::exists('companies','id')->wereIn('id', $companiesIds->toArray()); 
]);

after

$names = collect(['foo', 'bar']);
$companiesIds = collect([1, 2]);

$request->validate([
    'first_name' => Rule::in($names),
    'company' => Rule::exists('companies', 'id')->wereIn('id', $companiesIds); //no need to chain ->toArray()
]);

i didn't write tests for that behavior cause i felt i will have to repeat some methods inside or use data providers ValidationExistsRuleTest ... and also the query builder behavior is already been tested ... so if it's ok to duplicate am ok to write them

@taylorotwell taylorotwell merged commit 2534e00 into laravel:master Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants