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

Laravel 5

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 the PHP empty evaluates to true

Signature

The signature of the blank function is:

function blank(
    $value
);

Example Use

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

// Set a value to null.
$testValue = null;

if (blank($testValue)) {
    // Perform some action when the value is blank.
} else {
    // Perform a different action when the
    // supplied value is not blank.
}

Start the Discussion

Leave a comment

Subscribe to our newsletter