Skip to content
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

[5.6] Allow to pass collection to validation rules #23875

Merged
merged 1 commit into from
Apr 17, 2018
Merged

[5.6] Allow to pass collection to validation rules #23875

merged 1 commit into from
Apr 17, 2018

Conversation

jerguslejko
Copy link
Contributor

This PR makes necessary changes to allow for passing Illuminate\Support\Collection objects to Rule::in() and Rule::notIn() methods.

Thanks

@jerguslejko jerguslejko changed the title Allow to pass collection to validation rules [5.6] Allow to pass collection to validation rules Apr 13, 2018
* @return \Illuminate\Validation\Rules\In
*/
public static function in($values)
{
if ($values instanceof Collection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be generalized to Illuminate\Contracts\Support\Arrayable that Collection implements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'd need to rewrite In and NotIn rules to accept array and collections then.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since Arrayable contains the toArray method all you would need to change was the condition I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see you point now. Sorry guys.

I'd argue that Arrayable is implemented by following classes: Request, LengthAwarePaginator, MessageBag, Fluent etc.

Still think that Collection & array are the way to go.

@taylorotwell taylorotwell merged commit e3d958b into laravel:5.6 Apr 17, 2018
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.

4 participants