Skip to content

[12.x] Add filled_any and blank_any helpers with tests and types #56721

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

Open
wants to merge 2 commits into
base: 12.x
Choose a base branch
from

Conversation

leopaulo88
Copy link

Add filled_any and blank_any helpers with tests and types

Motivation

Laravel already provides the filled() and blank() helpers to check whether a single value is "filled" or "blank".
In practice, developers often need to check multiple values at once (for example, when at least one of several form fields must be provided).
Currently this requires verbose || or && checks.

Implementation

This PR introduces two new helpers in Illuminate/Support/helpers.php:

  • filled_any(...$values) → returns true if at least one of the given values is filled.
  • blank_any(...$values) → returns true if at least one of the given values is blank.

In addition:

  • Tests were added in SupportHelpersTest.php to cover the new helpers.
  • PHPStan type assertions were added in types/Support/Helpers.php to refine type inference.

Examples

// Before
if (filled($request->name) || filled($request->email)) {
    // ...
}

// After
if (filled_any($request->name, $request->email)) {
    // ...
}

if (blank_any($request->password, $request->password_confirmation)) {
    // ...
}

Backward Compatibility

This change is fully backward compatible.
It only introduces two new global helpers without altering the behavior of existing ones.

@shaedrich
Copy link
Contributor

Is there a reason why you didn't just change the existing filled() and blank() helpers?

@leopaulo88
Copy link
Author

Is there a reason why you didn't just change the existing filled() and blank() helpers?

Thanks for the feedback 🙏

I considered extending the existing filled() and blank() helpers, but I decided against it mainly for backward compatibility and clarity:

  • filled() and blank() are widely used today with the expectation of checking a single value.
  • Changing their signature to accept multiple arguments would introduce ambiguity (filled($a, $b) → should it return true if all are filled, or if any is filled?).
  • Adding new helpers (filled_any, blank_any) avoids breaking existing behavior and makes the intent explicit when working with multiple values.

This way, developers can continue using filled()/blank() as they always have, while still having a clear option for the “multiple values” case.

@shaedrich
Copy link
Contributor

shaedrich commented Aug 23, 2025

Changing their signature to accept multiple arguments would introduce ambiguity (filled($a, $b) → should it return true if all are filled, or if any is filled?).

Makes sense—thanks for the explanation 👍🏻

@leopaulo88
Copy link
Author

The failing Windows job seems unrelated to this change.
It fails on Illuminate\Tests\Integration\Session\DatabaseSessionHandlerTest::test_garbage_collector,
while this PR only adds new helpers (filled_any / blank_any) in the Support component.

Happy to rebase or re-run the CI if needed. 🙂

@leopaulo88 leopaulo88 changed the title Add filled_any and blank_any helpers with tests and types [12.x] Add filled_any and blank_any helpers with tests and types Aug 24, 2025
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