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


PHP Builder::distinct方法代码示例

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


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

示例1: distinct

 /**
  * Force the query to only return distinct results.
  *
  * @return $this 
  * @static 
  */
 public static function distinct()
 {
     return \Illuminate\Database\Query\Builder::distinct();
 }
开发者ID:satriashp,项目名称:tour,代码行数:10,代码来源:_ide_helper.php

示例2: addSelectQuery

 /**
  * Add selects to query builder
  * @param \Illuminate\Database\Query\Builder $query object is by reference
  */
 protected function addSelectQuery($query)
 {
     // Convert id into clients.id as id
     // Convert host.serverNum into hosts.server_num as host.serverNum ...
     // This one is odd becuase if column is in this entity, use COLUMN names
     // not property names because we have to transformStore next which requires column style.
     // BUT if column is subentity, then use entity names not colum names because we have already transformed the subentity
     // ex:
     /*array:9 [▼
         0 => "id"
         1 => "name"
         2 => "addressID"
         3 => "host.key"
         4 => "host.serverNum"
         5 => "address.address"
         6 => "address.city"
         7 => "address.stateKey"
         8 => "disabled"
       ]*/
     // Translates to
     /*
             array:9 [▼
      0 => "clients.id as id"
      1 => "clients.name as name"
      2 => "clients.address_id as address_id"
      3 => "hosts.key as host.key"
      4 => "hosts.server_num as host.serverNum"
      5 => "addresses.address as address.address"
      6 => "addresses.city as address.city"
      7 => "addresses.state as address.stateKey"
      8 => "clients.disabled as disabled"
             ]
     */
     $selects = [];
     if (isset($this->select)) {
         foreach ($this->select as $select) {
             $mappedSelect = $this->map($select, true);
             // host.serverNum
             list($table, $item) = explode('.', $select);
             if (str_contains($mappedSelect, '.')) {
                 list($table, $item) = explode('.', $mappedSelect);
                 $selects[] = "{$select} as {$table}.{$item}";
             } else {
                 $selects[] = "{$select} as {$item}";
             }
         }
     }
     // Add withCount (count column)
     if ($this->withCount) {
         $selects[] = DB::raw('count(*) as count');
     }
     $query->select($selects ?: ['*']);
     // Add distinct
     if ($this->distinct) {
         $query->distinct();
     }
 }
开发者ID:mreschke,项目名称:repository,代码行数:61,代码来源:DbStore.php


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