Add a "where not null" clause to the query.
public whereNotNull ( string $column, string $boolean = 'and' ) : |
||
$column | string | |
$boolean | string | |
리턴 |
/** * Add a "where" clause to the given query. * * @param \Illuminate\Database\Query\Builder $query * @param string $key * @param string $extraValue * @return void */ protected function addWhere($query, $key, $extraValue) { if ($extraValue === 'NULL') { $query->whereNull($key); } elseif ($extraValue === 'NOT_NULL') { $query->whereNotNull($key); } else { $query->where($key, $extraValue); } }
/** * Add a "where" clause to the given query. * * @param \Illuminate\Database\Query\Builder $query * @param string $key * @param string $extraValue * @return void */ protected function addWhere($query, $key, $extraValue) { if ($extraValue === 'NULL') { $query->whereNull($key); } elseif ($extraValue === 'NOT_NULL') { $query->whereNotNull($key); } elseif (Str::startsWith($extraValue, '!')) { $query->where($key, '!=', mb_substr($extraValue, 1)); } else { $query->where($key, $extraValue); } }
/** * like wheres function ,call by internal * @param array $conds * @return $this */ protected function _wheres($conds) { foreach ($conds as $field => $opAndVal) { if (is_null($opAndVal)) { $opAndVal = [null]; } $opAndVal = (array) $opAndVal; $op = strtolower(count($opAndVal) == 1 ? '=' : $opAndVal[0]); $val = last($opAndVal); $field = str_contains($field, '.') ? $field : $this->_table . '.' . $field; switch ($op) { case 'in': if (count($val) == 1) { $this->_operator->where($field, '=', $val[0]); } else { $this->_operator->whereIn($field, $val); } break; case 'notin': if (count($val) == 1) { $this->_operator->where($field, '<>', $val[0]); } else { $this->_operator->whereNotIn($field, $val); } break; case 'between': $this->_operator->whereBetween($field, $val); break; case 'notbetween': $this->_operator->whereNotBetween($field, $val); break; case 'null': if ($val) { $this->_operator->whereNull($field); } else { $this->_operator->whereNotNull($field); } break; case 'raw': $this->_operator->whereRaw($val); break; default: $this->_operator->where($field, $op, $val); } } return $this; }
/** * Add a "where not null" clause to the query. * * @param string $column * @param string $boolean * @return \Illuminate\Database\Query\Builder|static * @static */ public static function whereNotNull($column, $boolean = 'and') { return \Illuminate\Database\Query\Builder::whereNotNull($column, $boolean); }
/** * Force the result set to only included soft deletes. * * @return \Illuminate\Database\Eloquent\Builder|static */ public function onlyTrashed() { $this->withTrashed(); $this->query->whereNotNull($this->model->getQualifiedDeletedAtColumn()); return $this; }
/** * Add where to query builder * @param \Illuminate\Database\Query\Builder $query * @param array $subentity = null only add wheres with this subeneity */ protected function addWhereQuery($query, $subentity = null) { // Ex with both filter and where: select * from `dms` where (`key` like ? or `name` like ?) and `disabled` = ? if (isset($this->where)) { foreach ($this->where as $where) { #$table = $where['table']; $column = $where['column']; $operator = $where['operator']; $value = $where['value']; if ($operator == 'in') { #$query->whereIn("$table.$column", $value); $query->whereIn($column, $value); } elseif ($operator == 'null') { if ($value) { $query->whereNull($column); } else { $query->whereNotNull($column); } } else { #$query->where("$table.$column", $operator, $value); $query->where($column, $operator, $value); } } } }
/** * Query scope for only published data. * * @param \Illuminate\Database\Query\Builder $query * * @return \Illuminate\Database\Query\Builder */ public function scopeOnlyPublished($query) { return $query->whereNotNull(self::PUBLISHED_AT); }