Laravel 5: Determining if a Variable Holds a Value With blank

April 15, 2018 —John Koster

The blank function is used to determine if the provided value contains a value that is not null, or a non empty value. It can be useful to check arguments supplied to functions for values without having to check many different types specifically. A value is considered blank or empty if any of the following conditions are true:

  • The value is null,
  • The value is a string and contains only whitespace or is of length 0,
  • The value is not numeric,
  • The value is not a boolean value,
  • The value is a Countable object and contains no items,
  • the PHP empty evaluates to true

#Signature

The signature of the blank function is:

1function blank(
2 $value
3);

#Example Use

The following example demonstrates the basic usage of the blank function:

1// Set a value to null.
2$testValue = null;
3 
4if (blank($testValue)) {
5 // Perform some action when the value is blank.
6} else {
7 // Perform a different action when the
8 // supplied value is not blank.
9}

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.