Illuminate\Support\Collection::filter PHP Method

filter() public method

Run a filter over each of the items.
public filter ( callable $callback = null ) : static
$callback callable
return static
    public function filter(callable $callback = null)
    {
        if ($callback) {
            return new static(Arr::where($this->items, $callback));
        }
        return new static(array_filter($this->items));
    }

Usage Example

 /**
  * Get an attribute by name
  * @param string $name Attribute name
  * @return ConfigurationAttribute|null
  * @since 1.0
  */
 public function getAttribute($name, $returnValue = true)
 {
     $attribute = $this->attributes->filter(function ($attr) use($name) {
         /** @var ConfigurationAttribute $attr */
         return $attr->getName() == $name;
     })->first();
     return $returnValue && $attribute ? $attribute->getValue() : $attribute;
 }
All Usage Examples Of Illuminate\Support\Collection::filter