本文整理汇总了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();
}
示例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();
}
}