Skip to content

Commit dfc1613

Browse files
committed
Better useCollections
1 parent fa8f9aa commit dfc1613

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Builder extends BaseBuilder
8383
*
8484
* @var boolean
8585
*/
86-
protected $use_collection;
86+
protected $useCollections;
8787

8888
/**
8989
* Create a new query builder instance.
@@ -96,8 +96,7 @@ public function __construct(Connection $connection, Processor $processor)
9696
$this->grammar = new Grammar;
9797
$this->connection = $connection;
9898
$this->processor = $processor;
99-
$s = explode('.', \Illuminate\Foundation\Application::VERSION);
100-
$this->use_collection = (10 * $s[0] + $s[1]) >= 53;
99+
$this->useCollections = version_compare(\Illuminate\Foundation\Application::VERSION, '5.3.0', '>=');
101100
}
102101

103102
/**
@@ -268,7 +267,7 @@ public function getFresh($columns = [])
268267
$results = iterator_to_array($this->collection->aggregate($pipeline, $options));
269268

270269
// Return results
271-
return $this->use_collection ? new Collection($results) : $results;
270+
return $this->useCollections ? new Collection($results) : $results;
272271
}
273272

274273
// Distinct query
@@ -283,7 +282,7 @@ public function getFresh($columns = [])
283282
$result = $this->collection->distinct($column);
284283
}
285284

286-
return $this->use_collection ? new Collection($result) : $result;
285+
return $this->useCollections ? new Collection($result) : $result;
287286
}
288287

289288
// Normal query
@@ -327,7 +326,7 @@ public function getFresh($columns = [])
327326

328327
// Return results as an array with numeric keys
329328
$results = iterator_to_array($cursor, false);
330-
return $this->use_collection ? new Collection($results) : $results;
329+
return $this->useCollections ? new Collection($results) : $results;
331330
}
332331
}
333332

@@ -578,7 +577,7 @@ public function pluck($column, $key = null)
578577
{
579578
$results = $this->get(is_null($key) ? [$column] : [$column, $key]);
580579

581-
return $this->use_collection ? $results->pluck($column, $key) : Arr::pluck($results, $column, $key);
580+
return $this->useCollections ? $results->pluck($column, $key) : Arr::pluck($results, $column, $key);
582581
}
583582

584583
/**

0 commit comments

Comments
 (0)