Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[12.x] Introducing Collection hasAll Method #55770

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

Conversation

devajmeireles
Copy link
Contributor

Previous attempt: #26543


This PR adds the hasAll method to collections. Although this method has already been attempted in the past, I believe that today, we live in a new moment where it can be useful in our daily lives.

To exemplify the real benefit of this method, a few days ago I had to do the same, but manually:

// ...

if (empty(array_diff([
    'file_content',
    'file_extension',
], array_keys($data))) === false) {
    return $next($data);
}

Although we could achieve this goal through Macros, having it as part of the framework would facilitate our use cases:

collect(['file_content' => 'iVBORw0KGgoAA...', 'file_extension' => 'jpg'])
    ->hasAll('file_content', 'file_extension'); // true

@henzeb
Copy link
Contributor

henzeb commented May 19, 2025

Is this more or less a ensure function that ensures all keys exists in all items?

@taylorotwell
Copy link
Member

This is still treating the collection like a single object IMO. Collections are supposed to be collections of items.

@devajmeireles
Copy link
Contributor Author

This is still treating the collection like a single object IMO. Collections are supposed to be collections of items.

Makes sense. I agree with you. I'll try to target it to the Arr helper.

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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.