protected function filterOptionsBySearch($options, $query)
    {
        $filteredOptions = [];

        $optionMatchesSearch = function ($words, $option) {
            foreach ($words as $word) {
                $word = trim($word);
                if (!strlen($word)) {
                    continue;
                }

                if (!Str::contains(Str::lower($option), $word)) {
                    return false;
                }
            }

            return true;
        };

        /*
         * Exact
         */
        foreach ($options as $index => $option) {
            if (Str::is(Str::lower($option), $query)) {
                $filteredOptions[$index] = $option;
                unset($options[$index]);
            }
        }

        /*
         * Fuzzy
         */
        $words = explode(' ', $query);
        foreach ($options as $index => $option) {
            if ($optionMatchesSearch($words, $option)) {
                $filteredOptions[$index] = $option;
            }
        }

        return $filteredOptions;
    }
protected function filterOptionsBySearch($options, $query)
    {
        $filteredOptions = [];

        $optionMatchesSearch = function ($words, $option) {
            foreach ($words as $word) {
                $word = trim($word);
                if (!strlen($word)) {
                    continue;
                }

                if (!Str::contains(Str::lower($option), $word)) {
                    return false;
                }
            }

            return true;
        };

        /*
         * Exact
         */
        foreach ($options as $index => $option) {
            if (Str::is(Str::lower($option), $query)) {
                $filteredOptions[$index] = $option;
                unset($options[$index]);
            }
        }

        /*
         * Fuzzy
         */
        $words = explode(' ', $query);
        foreach ($options as $index => $option) {
            if ($optionMatchesSearch($words, $option)) {
                $filteredOptions[$index] = $option;
            }
        }

        return $filteredOptions;
    }
protected function filterOptionsBySearch ( $ options , $ query ) { $ filteredOptions = [ ] ; $ optionMatchesSearch = function ( $ words , $ option ) { foreach ( $ words as $ word ) { $ word = trim ( $ word ) ; if ( ! strlen ( $ word ) ) { continue ; } if ( ! Str :: contains ( Str :: lower ( $ option ) , $ word ) ) { return false ; } } return true ; } ; /*
         * Exact
         */ foreach ( $ options as $ index => $ option ) { if ( Str :: is ( Str :: lower ( $ option ) , $ query ) ) { $ filteredOptions [ $ index ] = $ option ; unset ( $ options [ $ index ] ) ; } } /*
         * Fuzzy
         */ $ words = explode ( ' ' , $ query ) ; foreach ( $ options as $ index => $ option ) { if ( $ optionMatchesSearch ( $ words , $ option ) ) { $ filteredOptions [ $ index ] = $ option ; } } return $ filteredOptions ; }
Filters an array of options by a search term.
@param array $options
@param string $query
@return array
Filters an array of options by a search term .