├── .github └── FUNDING.yml ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Any.php └── AnyServiceProvider.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: nunomaduro 4 | patreon: nunomaduro 5 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Nuno Maduro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Any example 3 |

4 | 5 |

6 | Build Status 7 | Total Downloads 8 | Latest Version 9 | License 10 |

11 | 12 | ## About laravel-any 13 | 14 | laravel-any was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is an Laravel collection macro that determine if any item from the collection passes the given truth test. 15 | 16 | ## Installation & Usage 17 | 18 | > **Requires [PHP 7.2+](https://php.net/releases/)** 19 | 20 | Create your package using [Composer](https://getcomposer.org): 21 | 22 | ```bash 23 | composer require nunomaduro/laravel-any 24 | ``` 25 | 26 | How to use: 27 | 28 | ```php 29 | $users = User::all(); 30 | 31 | // Returns `true` if the collection is not empty. 32 | $users->any(); 33 | 34 | // Returns `true` if there is a user with a paid plan. 35 | $users->any(fn ($user) => $user->has_paid_plan); 36 | 37 | // Returns `true` if there is a user with a paid plan. 38 | $users->any->has_paid_plan; 39 | ``` 40 | 41 | ## Contributing 42 | 43 | Thank you for considering to contribute to laravel-any. All the contribution guidelines are mentioned [here](CONTRIBUTING.md). 44 | 45 | You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: [@enunomaduro](https://twitter.com/enunomaduro) 46 | 47 | ## Support the development 48 | **Do you like this project? Support it by donating** 49 | 50 | - PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L) 51 | - Patreon: [Donate](https://www.patreon.com/nunomaduro) 52 | 53 | ## License 54 | 55 | laravel-any is an open-sourced software licensed under the [MIT license](LICENSE.md). 56 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nunomaduro/laravel-any", 3 | "description": "Determine if any item from the collection passes the given truth test.", 4 | "keywords": ["php", "laravel", "collection", "any", "package"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Nuno Maduro", 9 | "email": "enunomaduro@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": "^7.2", 14 | "laravel/framework": "^6.0 || ^7.0" 15 | }, 16 | "require-dev": { 17 | "nunomaduro/pest": "^0.1" 18 | }, 19 | "autoload-dev": { 20 | "psr-4": { 21 | "Tests\\": "tests/" 22 | } 23 | }, 24 | "minimum-stability": "dev", 25 | "prefer-stable": true, 26 | "autoload": { 27 | "psr-4": { 28 | "NunoMaduro\\LaravelAny\\": "src/" 29 | } 30 | }, 31 | "config": { 32 | "sort-packages": true, 33 | "preferred-install": "dist" 34 | }, 35 | "scripts": { 36 | "test:unit": "pest", 37 | "test": [ 38 | "@test:unit" 39 | ] 40 | }, 41 | "extra": { 42 | "laravel": { 43 | "providers": [ 44 | "NunoMaduro\\LaravelAny\\AnyServiceProvider" 45 | ] 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Any.php: -------------------------------------------------------------------------------- 1 | getIterator(); 21 | 22 | if (is_null($callback)) { 23 | $callback = function ($value): bool { 24 | return (bool) $value; 25 | }; 26 | } 27 | 28 | foreach ($iterable as $key => $value) { 29 | if ($callback($value, $key)) { 30 | return true; 31 | } 32 | } 33 | 34 | return false; 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/AnyServiceProvider.php: -------------------------------------------------------------------------------- 1 |