/** * Counts current query * * @return int */ private function count() { $query = $this->query; // if its a normal query ( no union, having or distinct ) replace the select with static text to improve performance $myQuery = clone $query; if (!Str::contains(Str::lower($myQuery->toSql()), ['union', 'having', 'distinct'])) { $myQuery->select($this->connection->raw("'1' as row_count")); } return $this->connection->table($this->connection->raw('(' . $myQuery->toSql() . ') count_row_table'))->setBindings($myQuery->getBindings())->count(); }
/** * Counts current query * * @return int */ private function count() { $query = $this->query; // if its a normal query ( no union ) replace the select with static text to improve performance $myQuery = clone $query; if (!preg_match('/UNION/i', strtoupper($myQuery->toSql()))) { $myQuery->select($this->connection->raw("'1' as row_count")); } return $this->connection->table($this->connection->raw('(' . $myQuery->toSql() . ') count_row_table'))->setBindings($myQuery->getBindings())->count(); }