8000 [9.x] Modify DatabaseRule to accept Arrayable instance inside where methods by amaelftah · Pull Request #39621 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] Modify DatabaseRule to accept Arrayable instance inside where methods #39621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

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
0