当前位置: 首页>>代码示例>>PHP>>正文


PHP Builder::whereNull方法代码示例

本文整理汇总了PHP中Illuminate\Database\Query\Builder::whereNull方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereNull方法的具体用法?PHP Builder::whereNull怎么用?PHP Builder::whereNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Query\Builder的用法示例。


在下文中一共展示了Builder::whereNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addWhere

 /**
  * 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);
     }
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:18,代码来源:DatabasePresenceVerifier.php

示例2: addWhere

 /**
  * 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);
     }
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:20,代码来源:DatabasePresenceVerifier.php

示例3: scopeForModel

 /**
  * Constrain a query to an ability for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function scopeForModel($query, Model $model)
 {
     $query->where(function ($query) use($model) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model) {
             $query->whereNull('entity_id');
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
开发者ID:Gummibeer,项目名称:bouncer,代码行数:19,代码来源:Ability.php

示例4: _wheres

 /**
  * 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;
 }
开发者ID:kyleing,项目名称:laravel-tool,代码行数:52,代码来源:DBOperator.php

示例5: whereNull

 /**
  * Add a "where null" clause to the query.
  *
  * @param string $column
  * @param string $boolean
  * @param bool $not
  * @return $this 
  * @static 
  */
 public static function whereNull($column, $boolean = 'and', $not = false)
 {
     return \Illuminate\Database\Query\Builder::whereNull($column, $boolean, $not);
 }
开发者ID:satriashp,项目名称:tour,代码行数:13,代码来源:_ide_helper.php

示例6: scopeForModel

 /**
  * Constrain a query to an permission for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model|string  $model
  * @param  bool  $strict
  * @return void
  */
 public function scopeForModel($query, $model, $strict = false)
 {
     $model = is_string($model) ? new $model() : $model;
     $query->where(function ($query) use($model, $strict) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model, $strict) {
             // If the model does not exist, we want to search for blanket permissions
             // that cover all instances of this model. If it does exist, we only
             // want to find blanket permissions if we're not using strict mode.
             if (!$model->exists || !$strict) {
                 $query->whereNull('entity_id');
             }
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
开发者ID:devonzara,项目名称:bouncer,代码行数:26,代码来源:Permission.php

示例7: parseFilter

 /**
  * Parse the remaining filter params
  *
  * @param  array $filterParams
  * @return void
  */
 protected function parseFilter($filterParams)
 {
     $supportedPostfixes = ['st' => '<', 'gt' => '>', 'min' => '>=', 'max' => '<=', 'lk' => 'LIKE', 'not-lk' => 'NOT LIKE', 'in' => 'IN', 'not-in' => 'NOT IN', 'not' => '!='];
     $supportedPrefixesStr = implode('|', $supportedPostfixes);
     $supportedPostfixesStr = implode('|', array_keys($supportedPostfixes));
     foreach ($filterParams as $filterParamKey => $filterParamValue) {
         $keyMatches = [];
         //Matches every parameter with an optional prefix and/or postfix
         //e.g. not-title-lk, title-lk, not-title, title
         $keyRegex = '/^(?:(' . $supportedPrefixesStr . ')-)?(.*?)(?:-(' . $supportedPostfixesStr . ')|$)/';
         preg_match($keyRegex, $filterParamKey, $keyMatches);
         if (!isset($keyMatches[3])) {
             if (strtolower(trim($filterParamValue)) == 'null') {
                 $comparator = 'NULL';
             } else {
                 $comparator = '=';
             }
         } else {
             if (strtolower(trim($filterParamValue)) == 'null') {
                 $comparator = 'NOT NULL';
             } else {
                 $comparator = $supportedPostfixes[$keyMatches[3]];
             }
         }
         $column = $keyMatches[2];
         if ($comparator == 'IN') {
             $values = explode(',', $filterParamValue);
             $this->query->whereIn($column, $values);
         } else {
             if ($comparator == 'NOT IN') {
                 $values = explode(',', $filterParamValue);
                 $this->query->whereNotIn($column, $values);
             } else {
                 $values = explode('|', $filterParamValue);
                 if (count($values) > 1) {
                     $this->query->where(function ($query) use($column, $comparator, $values) {
                         foreach ($values as $value) {
                             if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
                                 $value = preg_replace('/(^\\*|\\*$)/', '%', $value);
                             }
                             //Link the filters with AND of there is a "not" and with OR if there's none
                             if ($comparator == '!=' || $comparator == 'NOT LIKE') {
                                 $query->where($column, $comparator, $value);
                             } else {
                                 $query->orWhere($column, $comparator, $value);
                             }
                         }
                     });
                 } else {
                     $value = $values[0];
                     if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
                         $value = preg_replace('/(^\\*|\\*$)/', '%', $value);
                     }
                     if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
                         $this->query->whereNull($column, 'and', $comparator == 'NOT NULL');
                     } else {
                         $this->query->where($column, $comparator, $value);
                     }
                 }
             }
         }
     }
 }
开发者ID:marcelgwerder,项目名称:laravel-api-handler,代码行数:69,代码来源:Parser.php

示例8: generateNullConditionFromHasOneOrMany

 private function generateNullConditionFromHasOneOrMany(HasOneOrMany $relation)
 {
     $this->query = $this->query->whereNull($relation->getForeignKey());
 }
开发者ID:brazenvoid,项目名称:better-eloquent,代码行数:4,代码来源:JoinBuilder.php

示例9: addWhereQuery

 /**
  * 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);
             }
         }
     }
 }
开发者ID:mreschke,项目名称:repository,代码行数:30,代码来源:DbStore.php

示例10: parseFilter

 /**
  * Parse the remaining filter params
  *
  * @param  array $filterParams
  * @return void
  */
 protected function parseFilter($filterParams)
 {
     $supportedPostfixes = ['st' => '<', 'gt' => '>', 'min' => '>=', 'max' => '<=', 'lk' => 'LIKE', 'not-lk' => 'NOT LIKE', 'in' => 'IN', 'not-in' => 'NOT IN', 'not' => '!='];
     $supportedPrefixesStr = implode('|', $supportedPostfixes);
     $supportedPostfixesStr = implode('|', array_keys($supportedPostfixes));
     foreach ($filterParams as $filterParamKey => $filterParamValue) {
         $keyMatches = [];
         //Matches every parameter with an optional prefix and/or postfix
         //e.g. not-title-lk, title-lk, not-title, title
         $keyRegex = '/^(?:(' . $supportedPrefixesStr . ')-)?(.*?)(?:-(' . $supportedPostfixesStr . ')|$)/';
         preg_match($keyRegex, $filterParamKey, $keyMatches);
         if (!isset($keyMatches[3])) {
             if (strtolower(trim($filterParamValue)) == 'null') {
                 $comparator = 'NULL';
             } else {
                 $comparator = '=';
             }
         } else {
             if (strtolower(trim($filterParamValue)) == 'null') {
                 $comparator = 'NOT NULL';
             } else {
                 $comparator = $supportedPostfixes[$keyMatches[3]];
             }
         }
         $column = $keyMatches[2];
         //resolve a relation->relation_column if we are using an eloquent builder.
         if (strpos($column, '->') !== false && $this->isEloquentBuilder) {
             $model = $this->builder->getModel();
             //get the relation and the column in the relation
             $relationComponents = explode('->', $column);
             if (!method_exists($model, $relationComponents[0])) {
                 throw new ApiHandlerException('UnknownResourceRelation', ['relation' => $relationComponents[0]]);
             }
             $relation = call_user_func([$model, $relationComponents[0]]);
             $relationColumn = $relationComponents[1];
             $relationType = $this->getRelationType($relation);
             if ($relationType === 'BelongsTo') {
                 $firstKey = $relation->getQualifiedForeignKey();
                 $secondKey = $relation->getQualifiedOtherKeyName();
             } else {
                 if ($relationType === 'HasMany' || $relationType === 'HasOne') {
                     $firstKey = $relation->getQualifiedParentKeyName();
                     $secondKey = $relation->getForeignKey();
                 } else {
                     if ($relationType === 'BelongsToMany') {
                         $firstKey = $relation->getQualifiedParentKeyName();
                         $secondKey = $relation->getRelated()->getQualifiedKeyName();
                     }
                 }
             }
             //get the table to join to
             $joinTable = $relation->getRelated()->getTable();
             //do the join
             $this->query->join($joinTable, $firstKey, '=', $secondKey);
             //modify the $column name and continue parsing.
             $column = $joinTable . '.' . $relationColumn;
             $this->query->addSelect($model->getTable() . '.*');
         }
         //should we be using an eloquent builder, append the table name to every column to differentiate from joined columns.
         if ($this->isEloquentBuilder) {
             if (strpos($column, '.') === false) {
                 $column = $this->builder->getModel()->getTable() . '.' . $column;
             }
         }
         if ($comparator == 'IN') {
             $values = explode(',', $filterParamValue);
             $this->query->whereIn($column, $values);
         } else {
             if ($comparator == 'NOT IN') {
                 $values = explode(',', $filterParamValue);
                 $this->query->whereNotIn($column, $values);
             } else {
                 $values = explode('|', $filterParamValue);
                 if (count($values) > 1) {
                     $this->query->where(function ($query) use($column, $comparator, $values) {
                         foreach ($values as $value) {
                             if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
                                 $value = preg_replace('/(^\\*|\\*$)/', '%', $value);
                             }
                             //Link the filters with AND of there is a "not" and with OR if there's none
                             if ($comparator == '!=' || $comparator == 'NOT LIKE') {
                                 $query->where($column, $comparator, $value);
                             } else {
                                 $query->orWhere($column, $comparator, $value);
                             }
                         }
                     });
                 } else {
                     $value = $values[0];
                     if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
                         $value = preg_replace('/(^\\*|\\*$)/', '%', $value);
                     }
                     if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
                         $this->query->whereNull($column, 'and', $comparator == 'NOT NULL');
//.........这里部分代码省略.........
开发者ID:estebanprimost,项目名称:laravel-api-handler,代码行数:101,代码来源:Parser.php

示例11: scopeOnlyDrafted

 /**
  * Query scope for only drafted data.
  *
  * @param \Illuminate\Database\Query\Builder $query
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeOnlyDrafted($query)
 {
     return $query->whereNull(self::PUBLISHED_AT);
 }
开发者ID:aguaragazu,项目名称:LaravelStart,代码行数:11,代码来源:Publishable.php

示例12: scopeSimpleAbility

 /**
  * Constrain a query to simple abilities.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @return void
  */
 public function scopeSimpleAbility($query)
 {
     $query->whereNull("{$this->table}.entity_type");
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:10,代码来源:IsAbility.php

示例13: isAvailable

 /**
  * Modify the query to check for available jobs.
  *
  * @param  \Illuminate\Database\Query\Builder  $query
  * @return void
  */
 protected function isAvailable($query)
 {
     $query->where(function ($query) {
         $query->whereNull('reserved_at');
         $query->where('available_at', '<=', $this->getTime());
     });
 }
开发者ID:davidhemphill,项目名称:framework,代码行数:13,代码来源:DatabaseQueue.php

示例14: whereNull

 public function whereNull($column, $boolean = 'and', $not = false)
 {
     $column = is_string($column) ? snake_case($column) : $column;
     return parent::whereNull($column, $boolean, $not);
     // TODO: Change the autogenerated stub
 }
开发者ID:jgraffite,项目名称:snake2camel,代码行数:6,代码来源:QueryBuilder.php

示例15: scopeTopLevel

 /**
  * Returns categories that have no parents (top-level categories)
  *
  * @param \Illuminate\Database\Query\Builder $query
  *
  * @return \Illuminate\Database\Query\Builder $query
  */
 public function scopeTopLevel($query)
 {
     return $query->whereNull('parentCategoryId');
 }
开发者ID:stickableapp,项目名称:stickable-api,代码行数:11,代码来源:Category.php


注:本文中的Illuminate\Database\Query\Builder::whereNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。