/** * Force the query to only return distinct results. * * @return $this * @static */ public static function distinct() { return \Illuminate\Database\Query\Builder::distinct(); }
/** * 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(); } }