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

[10.x] Add hasAny function to ComponentAttributeBag, Allow multiple keys in has function #47569

Merged

Conversation

indykoning
Copy link
Contributor

@indykoning indykoning commented Jun 26, 2023

The has() function for the ComponentAttributeBag has been pulled in line with that of a collection, allowing the user to check existence for multiple keys' existence within the attribute bag more efficiently.
hasAny() did not exist at all before requiring creation of macros or methods such as

$isAnchor = count(
        $attributes
            ->only('href', ':href', 'v-bind:href')
            ->filter(null)
            ->getAttributes(),
    ) > 0;

to determine wether a href has been set.
After this change it is possible to shorten this to

$isAnchor = $attributes->filter(null)->hasAny('href', ':href', 'v-bind:href');

This was also functionality already available to collections, thus we have kept this functionality inline with it.

This is not a breaking change as the old function allowed only one argument to be passed, now it will allow one or more. And has the already expected behaviour of the has function.

@@ -77,7 +108,7 @@ public function has($key)
*/
public function missing($key)
{
return ! $this->has($key, $this->attributes);
Copy link
Contributor Author

@indykoning indykoning Jun 26, 2023

Choose a reason for hiding this comment

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

$this->attributes has been removed from this function as it was and is not supported in the has() function.

@indykoning indykoning changed the title Add hasAny function to ComponentAttributeBag, Allow multiple keys in has function [10.x] Add hasAny function to ComponentAttributeBag, Allow multiple keys in has function Jun 26, 2023
@taylorotwell taylorotwell merged commit 3558da8 into laravel:10.x Jun 26, 2023
16 checks passed
@indykoning indykoning deleted the feature/componentattributebag-hasany branch June 27, 2023 07:13
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.

None yet

2 participants