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

Skip to content

[8.x] Modify DatabaseRule to accept Arrayable instance inside where methods #39620

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

Closed

Conversation

amaelftah
Copy link
Contributor

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

* @return $this
*/
public function whereIn($column, array $values)
public function whereIn($column, $values)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change a method signature on a minor release since it's potentially breaking to anyone overwriting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

< 8000 /form>

got it ... should i close it and open a new one for 9.x ... or also in 9.x we don't won't to introduce breaking behavior like this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try master yeah

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