public function whereLike($field, $arguments, bool $ilike = false, bool $not = false, string $op = ''): self
    {
        // @note to me..
        // 'foo%'  Anything starts with "foo"
        // '%foo'  Anything ends with "foo"
        // '%foo%' Anything have "foo" in any position
        // 'f_o%'  Anything have "o" in the second position
        // 'f_%_%' Anything starts with "f" and are at least 3 characters in length
        // 'f%o'   Anything starts with "f" and ends with "o"

        $arguments = (array) $arguments;
        $searchArguments = array_slice($arguments, 0, 3);

        if ($arguments != null) {
            // eg: (??, ['%', 'apple', '%', 'id']), (%n, ['%', 'apple', '%', 'id'])
            $field = $this->agent->prepare($field, array_slice($arguments, 3));
        }

        $search = '';
        switch (count($searchArguments)) {
            case 1: // none, eg: 'apple', ['apple']
                [$start, $search, $end] = ['', $searchArguments[0], ''];
                break;
            case 2: // start/end, eg: ['%', 'apple'], ['apple', '%']
                if ($searchArguments[0] == '%') {
                    [$start, $search, $end] = ['%', $searchArguments[1], ''];
                } elseif ($searchArguments[1] == '%') {
                    [$start, $search, $end] = ['', $searchArguments[0], '%'];
                }
                break;
            case 3: // both, eg: ['%', 'apple', '%']
                [$start, $search, $end] = $searchArguments;
                break;
        }

        $search = trim((string) $search);
        if ($search == '') {
            throw new BuilderException('Like search cannot be empty!');
        }

        $not = $not ? 'NOT ' : '';

        if (is_string($field) && strpos($field, '(') === false) {
            $field = $this->prepareField($field, false);
        }

        $search = $end . $this->agent->escape($search, '%sl', false) . $start;

        $where = [];
        $fields = (array) $field;
        if (!$ilike) {
            foreach ($fields as $field) {
                $where[] = sprintf("%s %sLIKE '%s'", $field, $not, $search);
            }
        } else {
            foreach ($fields as $field) {
                if ($this->agent->isMysql()) {
                    $where[] = sprintf("lower(%s) %sLIKE lower('%s')", $field, $not, $search);
                } elseif ($this->agent->isPgsql()) {
                    $where[] = sprintf("%s %sILIKE '%s'", $field, $not, $search);
                }
            }
        }
        $where = count($where) > 1 ? '('. join(' OR ', $where) .')' : join(' OR ', $where);

        return $this->where($where);
    }
public function whereLike($field, $arguments, bool $ilike = false, bool $not = false, string $op = ''): self
    {
        // @note to me..
        // 'foo%'  Anything starts with "foo"
        // '%foo'  Anything ends with "foo"
        // '%foo%' Anything have "foo" in any position
        // 'f_o%'  Anything have "o" in the second position
        // 'f_%_%' Anything starts with "f" and are at least 3 characters in length
        // 'f%o'   Anything starts with "f" and ends with "o"

        $arguments = (array) $arguments;
        $searchArguments = array_slice($arguments, 0, 3);

        if ($arguments != null) {
            // eg: (??, ['%', 'apple', '%', 'id']), (%n, ['%', 'apple', '%', 'id'])
            $field = $this->agent->prepare($field, array_slice($arguments, 3));
        }

        $search = '';
        switch (count($searchArguments)) {
            case 1: // none, eg: 'apple', ['apple']
                [$start, $search, $end] = ['', $searchArguments[0], ''];
                break;
            case 2: // start/end, eg: ['%', 'apple'], ['apple', '%']
                if ($searchArguments[0] == '%') {
                    [$start, $search, $end] = ['%', $searchArguments[1], ''];
                } elseif ($searchArguments[1] == '%') {
                    [$start, $search, $end] = ['', $searchArguments[0], '%'];
                }
                break;
            case 3: // both, eg: ['%', 'apple', '%']
                [$start, $search, $end] = $searchArguments;
                break;
        }

        $search = trim((string) $search);
        if ($search == '') {
            throw new BuilderException('Like search cannot be empty!');
        }

        $not = $not ? 'NOT ' : '';

        if (is_string($field) && strpos($field, '(') === false) {
            $field = $this->prepareField($field, false);
        }

        $search = $end . $this->agent->escape($search, '%sl', false) . $start;

        $where = [];
        $fields = (array) $field;
        if (!$ilike) {
            foreach ($fields as $field) {
                $where[] = sprintf("%s %sLIKE '%s'", $field, $not, $search);
            }
        } else {
            foreach ($fields as $field) {
                if ($this->agent->isMysql()) {
                    $where[] = sprintf("lower(%s) %sLIKE lower('%s')", $field, $not, $search);
                } elseif ($this->agent->isPgsql()) {
                    $where[] = sprintf("%s %sILIKE '%s'", $field, $not, $search);
                }
            }
        }
        $where = count($where) > 1 ? '('. join(' OR ', $where) .')' : join(' OR ', $where);

        return $this->where($where);
    }
public function whereLike ( $ field , $ arguments , bool $ ilike = false , bool $ not = false , string $ op = '' ) : self { // @note to me.. // 'foo%'  Anything starts with "foo" // '%foo'  Anything ends with "foo" // '%foo%' Anything have "foo" in any position // 'f_o%'  Anything have "o" in the second position // 'f_%_%' Anything starts with "f" and are at least 3 characters in length // 'f%o'   Anything starts with "f" and ends with "o" $ arguments = ( array ) $ arguments ; $ searchArguments = array_slice ( $ arguments , 0 , 3 ) ; if ( $ arguments != null ) { // eg: (??, ['%', 'apple', '%', 'id']), (%n, ['%', 'apple', '%', 'id']) $ field = $ this -> agent -> prepare ( $ field , array_slice ( $ arguments , 3 ) ) ; } $ search = '' ; switch ( count ( $ searchArguments ) ) { case 1 : // none, eg: 'apple', ['apple'] [ $ start , $ search , $ end ] = [ '' , $ searchArguments [ 0 ] , '' ] ; break ; case 2 : // start/end, eg: ['%', 'apple'], ['apple', '%'] if ( $ searchArguments [ 0 ] == '%' ) { [ $ start , $ search , $ end ] = [ '%' , $ searchArguments [ 1 ] , '' ] ; } elseif ( $ searchArguments [ 1 ] == '%' ) { [ $ start , $ search , $ end ] = [ '' , $ searchArguments [ 0 ] , '%' ] ; } break ; case 3 : // both, eg: ['%', 'apple', '%'] [ $ start , $ search , $ end ] = $ searchArguments ; break ; } $ search = trim ( ( string ) $ search ) ; if ( $ search == '' ) { throw new BuilderException ( 'Like search cannot be empty!' ) ; } $ not = $ not ? 'NOT ' : '' ; if ( is_string ( $ field ) && strpos ( $ field , '(' ) === false ) { $ field = $ this -> prepareField ( $ field , false ) ; } $ search = $ end . $ this -> agent -> escape ( $ search , '%sl' , false ) . $ start ; $ where = [ ] ; $ fields = ( array ) $ field ; if ( ! $ ilike ) { foreach ( $ fields as $ field ) { $ where [ ] = sprintf ( "%s %sLIKE '%s'" , $ field , $ not , $ search ) ; } } else { foreach ( $ fields as $ field ) { if ( $ this -> agent -> isMysql ( ) ) { $ where [ ] = sprintf ( "lower(%s) %sLIKE lower('%s')" , $ field , $ not , $ search ) ; } elseif ( $ this -> agent -> isPgsql ( ) ) { $ where [ ] = sprintf ( "%s %sILIKE '%s'" , $ field , $ not , $ search ) ; } } } $ where = count ( $ where ) > 1 ? '(' . join ( ' OR ' , $ where ) . ')' : join ( ' OR ' , $ where ) ; return $ this -> where ( $ where ) ; }
Where like.
@param  string|array|Builder $field
@param  string|array         $arguments
@param  bool                 $ilike
@param  bool                 $not
@param  string               $op
@return self
Where like .