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


PHP Grammar::getOperators方法代码示例

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


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

示例1: where

 /**
  * Add a basic where clause to the query.
  *
  * @param  string|array|\Closure  $column
  * @param  string  $operator
  * @param  mixed   $value
  * @param  string  $boolean
  * @return $this
  *
  * @throws \InvalidArgumentException
  */
 public function where($column, $operator = null, $value = null, $boolean = 'and')
 {
     // If the column is an array, we will assume it is an array of key-value pairs
     // and can add them each as a where clause. We will maintain the boolean we
     // received when the method was called and pass it into the nested where.
     if (is_array($column)) {
         return $this->addArrayOfWheres($column, $boolean);
     }
     // Here we will make some assumptions about the operator. If only 2 values are
     // passed to the method, we will assume that the operator is an equals sign
     // and keep going. Otherwise, we'll require the operator to be passed in.
     if (func_num_args() == 2) {
         list($value, $operator) = [$operator, '='];
     } elseif ($this->invalidOperatorAndValue($operator, $value)) {
         throw new InvalidArgumentException('Illegal operator and value combination.');
     }
     // If the columns is actually a Closure instance, we will assume the developer
     // wants to begin a nested where statement which is wrapped in parenthesis.
     // We'll add that Closure to the query then return back out immediately.
     if ($column instanceof Closure) {
         return $this->whereNested($column, $boolean);
     }
     // If the given operator is not found in the list of valid operators we will
     // assume that the developer is just short-cutting the '=' operators and
     // we will set the operators to '=' and set the values appropriately.
     if (!in_array(strtolower($operator), $this->operators, true) && !in_array(strtolower($operator), $this->grammar->getOperators(), true)) {
         list($value, $operator) = [$operator, '='];
     }
     // If the value is a Closure, it means the developer is performing an entire
     // sub-select within the query and we will need to compile the sub-select
     // within the where clause to get the appropriate query record results.
     if ($value instanceof Closure) {
         return $this->whereSub($column, $operator, $value, $boolean);
     }
     // If the value is "null", we will just assume the developer wants to add a
     // where null clause to the query. So, we will allow a short-cut here to
     // that method for convenience so the developer doesn't have to check.
     if (is_null($value)) {
         return $this->whereNull($column, $boolean, $operator != '=');
     }
     // Now that we are working with just a simple query we can put the elements
     // in our array and add the query binding to our array of bindings that
     // will be bound to each SQL statements when it is finally executed.
     $type = 'Basic';
     $this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean');
     if (!$value instanceof Expression) {
         $this->addBinding($value, 'where');
     }
     return $this;
 }
开发者ID:hakoncms,项目名称:hakoncms,代码行数:61,代码来源:Builder.php

示例2: whereColumn

 /**
  * Add a "where" clause comparing two columns to the query.
  *
  * @param  string|array  $first
  * @param  string|null  $operator
  * @param  string|null  $second
  * @param  string|null  $boolean
  * @return \Illuminate\Database\Query\Builder|static
  */
 public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
 {
     // If the column is an array, we will assume it is an array of key-value pairs
     // and can add them each as a where clause. We will maintain the boolean we
     // received when the method was called and pass it into the nested where.
     if (is_array($first)) {
         return $this->addArrayOfWheres($first, $boolean, 'whereColumn');
     }
     // If the given operator is not found in the list of valid operators we will
     // assume that the developer is just short-cutting the '=' operators and
     // we will set the operators to '=' and set the values appropriately.
     if (!in_array(strtolower($operator), $this->operators, true) && !in_array(strtolower($operator), $this->grammar->getOperators(), true)) {
         list($second, $operator) = [$operator, '='];
     }
     $type = 'Column';
     $this->wheres[] = compact('type', 'first', 'operator', 'second', 'boolean');
     return $this;
 }
开发者ID:teckwei1993,项目名称:laravel-in-directadmin,代码行数:27,代码来源:Builder.php


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