2
2
3
3
use Closure ;
4
4
use Laravel \Database ;
5
- use Paginator ;
5
+ use Laravel \ Paginator ;
6
6
use Laravel \Database \Query \Grammars \Postgres ;
7
7
use Laravel \Database \Query \Grammars \SQLServer ;
8
8
@@ -140,7 +140,7 @@ public function distinct()
140
140
*/
141
141
public function select ($ columns = array ('* ' ))
142
142
{
143
- $ this ->selects = is_array ( $ columns ) ? $ columns : array ( $ columns ) ;
143
+ $ this ->selects = ( array ) $ columns ;
144
144
return $ this ;
145
145
}
146
146
@@ -158,7 +158,7 @@ public function join($table, $column1, $operator = null, $column2 = null, $type
158
158
{
159
159
// If the "column" is really an instance of a Closure, the developer is
160
160
// trying to create a join with a complex "ON" clause. So, we will add
161
- // the join, and then call the Closure with the join.
161
+ // the join, and then call the Closure with the join/
162
162
if ($ column1 instanceof Closure)
163
163
{
164
164
$ this ->joins [] = new Query \Join ($ type , $ table );
@@ -168,7 +168,7 @@ public function join($table, $column1, $operator = null, $column2 = null, $type
168
168
169
169
// If the column is just a string, we can assume that the join just
170
170
// has a simple on clause, and we'll create the join instance and
171
- // add the clause automatically for the developer .
171
+ // add the clause automatically for the develoepr .
172
172
else
173
173
{
174
174
$ join = new Query \Join ($ type , $ table );
@@ -283,7 +283,7 @@ public function or_where($column, $operator = null, $value = null)
283
283
*/
284
284
public function or_where_id ($ value )
285
285
{
286
- return $ this ->or_where ('id ' , '= ' , $ value );
286
+ return $ this ->or_where ('id ' , '= ' , $ value );
287
287
}
288
288
289
289
/**
@@ -395,15 +395,32 @@ public function or_where_not_null($column)
395
395
}
396
396
397
397
/**
398
- * Add nested constraints to the query.
398
+ * Add a nested where condition to the query.
399
399
*
400
400
* @param Closure $callback
401
401
* @param string $connector
402
402
* @return Query
403
403
*/
404
404
public function where_nested ($ callback , $ connector = 'AND ' )
405
405
{
406
- call_user_func ($ callback , $ this );
406
+ $ type = 'where_nested ' ;
407
+
408
+ // To handle a nested where statement, we will actually instantiate a new
409
+ // Query instance and run the callback over that instance, which will
410
+ // allow the developer to have a fresh query instance
411
+ $ query = new Query ($ this ->connection , $ this ->grammar , $ this ->from );
412
+
413
+ call_user_func ($ callback , $ query );
414
+
415
+ // Once the callback has been run on the query, we will store the nested
416
+ // query instance on the where clause array so that it's passed to the
417
+ // query's query grammar instance when building.
418
+ if ($ query ->wheres !== null )
419
+ {
420
+ $ this ->wheres [] = compact ('type ' , 'query ' , 'connector ' );
421
+ }
422
+
423
+ $ this ->bindings = array_merge ($ this ->bindings , $ query ->bindings );
407
424
408
425
return $ this ;
409
426
}
@@ -436,7 +453,7 @@ private function dynamic_where($method, $parameters)
436
453
437
454
foreach ($ segments as $ segment )
438
455
{
439
- // If the segment is not a boolean connector, we can assume it is
456
+ // If the segment is not a boolean connector, we can assume it it is
440
457
// a column name, and we'll add it to the query as a new constraint
441
458
// of the query's where clause and keep iterating the segments.
442
459
if ($ segment != '_and_ ' and $ segment != '_or_ ' )
@@ -475,7 +492,6 @@ public function group_by($column)
475
492
* @param string $column
476
493
* @param string $operator
477
494
* @param mixed $value
478
- * @return Query
479
495
*/
480
496
public function having ($ column , $ operator , $ value )
481
497
{
@@ -660,7 +676,7 @@ public function get($columns = array('*'))
660
676
public function aggregate ($ aggregator , $ columns )
661
677
{
662
678
// We'll set the aggregate value so the grammar does not try to compile
663
- // a SELECT clause on the query. If an aggregator is present, its own
679
+ // a SELECT clause on the query. If an aggregator is present, it's own
664
680
// grammar function will be used to build the SQL syntax.
665
681
$ this ->aggregate = compact ('aggregator ' , 'columns ' );
666
682
@@ -687,7 +703,7 @@ public function paginate($per_page = 20, $columns = array('*'))
687
703
{
688
704
// Because some database engines may throw errors if we leave orderings
689
705
// on the query when retrieving the total number of records, we'll drop
690
- // all of the orderings and put them back on the query.
706
+ // all of the ordreings and put them back on the query.
691
707
list ($ orderings , $ this ->orderings ) = array ($ this ->orderings , null );
692
708
693
709
$ total = $ this ->count (reset ($ columns ));
@@ -714,12 +730,12 @@ public function insert($values)
714
730
{
715
731
// Force every insert to be treated like a batch insert to make creating
716
732
// the binding array simpler since we can just spin through the inserted
717
- // rows as if there was more than one every time.
733
+ // rows as if there/ was more than one every time.
718
734
if ( ! is_array (reset ($ values ))) $ values = array ($ values );
719
735
720
736
$ bindings = array ();
721
737
722
- // We need to merge the insert values into the array of the query
738
+ // We need to merge the the insert values into the array of the query
723
739
// bindings so that they will be bound to the PDO statement when it
724
740
// is executed by the database connection.
725
741
foreach ($ values as $ value )
@@ -820,7 +836,7 @@ public function update($values)
820
836
/**
821
837
* Execute the query as a DELETE statement.
822
838
*
823
- * Optionally, an ID may be passed to the method to delete a specific row.
839
+ * Optionally, an ID may be passed to the method do delete a specific row.
824
840
*
825
841
* @param int $id
826
842
* @return int
@@ -837,7 +853,7 @@ public function delete($id = null)
837
853
838
854
$ sql = $ this ->grammar ->delete ($ this );
839
855
840
- return $ this ->connection ->query ($ sql , $ this ->bindings );
856
+ return $ this ->connection ->query ($ sql , $ this ->bindings );
841
857
}
842
858
843
859
/**
@@ -853,7 +869,7 @@ public function __call($method, $parameters)
853
869
}
854
870
855
871
// All of the aggregate methods are handled by a single method, so we'll
856
- // catch them all here and then pass them off to the aggregate method
872
+ // catch them all here and then pass them off to the agregate method
857
873
// instead of creating methods for each one of them.
858
874
if (in_array ($ method , array ('count ' , 'min ' , 'max ' , 'avg ' , 'sum ' )))
859
875
{
0 commit comments