public function filterRecursive($attribute, $value)
    {
        $collection = new Collection();

        // Iterate over all the items in the main collection
        $this->items->each(function ($item) use ($attribute, $value, &$collection) {
            if (!$this->hasProperty($attribute)) {
                return false;
            }

            if ($item->$attribute == $value) {
                $collection->push($item);

                // Check if item has any children
                if ($item->hasChildren()) {
                    $collection = $collection->merge($this->filterRecursive($attribute, $item->id));
                }
            }
        });

        return $collection;
    }
public function filterRecursive($attribute, $value)
    {
        $collection = new Collection();

        // Iterate over all the items in the main collection
        $this->items->each(function ($item) use ($attribute, $value, &$collection) {
            if (!$this->hasProperty($attribute)) {
                return false;
            }

            if ($item->$attribute == $value) {
                $collection->push($item);

                // Check if item has any children
                if ($item->hasChildren()) {
                    $collection = $collection->merge($this->filterRecursive($attribute, $item->id));
                }
            }
        });

        return $collection;
    }
public function filterRecursive ( $ attribute , $ value ) { $ collection = new Collection ( ) ; // Iterate over all the items in the main collection $ this -> items -> each ( function ( $ item ) use ( $ attribute , $ value , & $ collection ) { if ( ! $ this -> hasProperty ( $ attribute ) ) { return false ; } if ( $ item -> $ attribute == $ value ) { $ collection -> push ( $ item ) ; // Check if item has any children if ( $ item -> hasChildren ( ) ) { $ collection = $ collection -> merge ( $ this -> filterRecursive ( $ attribute , $ item -> id ) ) ; } } } ) ; return $ collection ; }
Filter items recursively.

@param string $attribute
@param mixed  $value

@return Collection
Filter items recursively .