66use DateTime ;
77use Closure ;
88
9+ use Illuminate \Database \Query \Builder as QueryBuilder ;
910use Illuminate \Database \Query \Expression ;
1011use Jenssegers \Mongodb \Connection ;
1112
12- class Builder extends \ Illuminate \ Database \ Query \Builder {
13+ class Builder extends QueryBuilder {
1314
1415 /**
1516 * The database collection
@@ -193,6 +194,7 @@ public function getFresh($columns = array())
193194 foreach ($ this ->columns as $ column )
194195 {
195196 $ key = str_replace ('. ' , '_ ' , $ column );
197+
196198 $ group [$ key ] = array ('$last ' => '$ ' . $ column );
197199 }
198200 }
@@ -374,17 +376,18 @@ public function insert(array $values)
374376 // Since every insert gets treated like a batch insert, we will have to detect
375377 // if the user is inserting a single document or an array of documents.
376378 $ batch = true ;
379+
377380 foreach ($ values as $ value )
378381 {
379382 // As soon as we find a value that is not an array we assume the user is
380383 // inserting a single document.
381- if (! is_array ($ value ))
384+ if ( ! is_array ($ value ))
382385 {
383386 $ batch = false ; break ;
384387 }
385388 }
386389
387- if (! $ batch ) $ values = array ($ values );
390+ if ( ! $ batch ) $ values = array ($ values );
388391
389392 // Batch insert
390393 $ result = $ this ->collection ->batchInsert ($ values );
@@ -405,7 +408,7 @@ public function insertGetId(array $values, $sequence = null)
405408
406409 if (1 == (int ) $ result ['ok ' ])
407410 {
408- if (! $ sequence )
411+ if (is_null ( $ sequence) )
409412 {
410413 $ sequence = '_id ' ;
411414 }
@@ -454,6 +457,7 @@ public function increment($column, $amount = 1, array $extra = array(), array $o
454457 $ this ->where (function ($ query ) use ($ column )
455458 {
456459 $ query ->where ($ column , 'exists ' , false );
460+
457461 $ query ->orWhereNotNull ($ column );
458462 });
459463
@@ -502,6 +506,7 @@ public function pluck($column)
502506 public function delete ($ id = null )
503507 {
504508 $ wheres = $ this ->compileWheres ();
509+
505510 $ result = $ this ->collection ->remove ($ wheres );
506511
507512 if (1 == (int ) $ result ['ok ' ])
@@ -577,13 +582,13 @@ public function push($column, $value = null, $unique = false)
577582 $ operator = $ unique ? '$addToSet ' : '$push ' ;
578583
579584 // Check if we are pushing multiple values.
580- $ multipleValues = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
585+ $ batch = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
581586
582587 if (is_array ($ column ))
583588 {
584589 $ query = array ($ operator => $ column );
585590 }
586- else if ($ multipleValues )
591+ else if ($ batch )
587592 {
588593 $ query = array ($ operator => array ($ column => array ('$each ' => $ value )));
589594 }
@@ -605,10 +610,10 @@ public function push($column, $value = null, $unique = false)
605610 public function pull ($ column , $ value = null )
606611 {
607612 // Check if we passed an associative array.
608- $ multipleValues = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
613+ $ batch = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
609614
610615 // If we are pulling multiple values, we need to use $pullAll.
611- $ operator = $ multipleValues ? '$pullAll ' : '$pull ' ;
616+ $ operator = $ batch ? '$pullAll ' : '$pull ' ;
612617
613618 if (is_array ($ column ))
614619 {
0 commit comments