Laravel 5: Checking if a Variable Holds a Value With filled

Laravel 5

The filled helper function is the logical opposite of the blank helper function, and can be used to quickly determine if the provided value has a non-null, or non-empty value. The provided $value is considered filled if any of the following conditions are met:

  • The value is not null,
  • The value is a string and contains non-whitespace characters with a length greater than 0,
  • The value is numeric, and contains value,
  • The value is boolean,
  • The value is a Countable object and contains items,
  • The the PHP empty evaluates to false

Signature

The signature of the filled function is:

function filled(
    $value
);

Example Use

The following example demonstrates the basic usage of the filled method and is the opposite of the example provided in the blank section:

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

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

Start the Discussion

Leave a comment

Subscribe to our newsletter