@@ -117,34 +117,55 @@ protected function validate_criteria($criteria) {
117
117
}
118
118
119
119
/**
120
+ * Register search parameters
120
121
* @param mixed $criteria
121
122
* @param null $value
122
123
*
123
124
* @return $this
124
125
* @throws InvalidWhereQueryCriteriaException
126
+ *
127
+ * Examples:
128
+ * $query->from("[email protected] ")->seen();
129
+ * $query->whereFrom("[email protected] ")->whereSeen();
130
+ * $query->where([["FROM" => "[email protected] "], ["SEEN"]]);
131
+ * $query->where(["FROM" => "[email protected] "])->where(["SEEN"]);
132
+ * $query->where(["FROM" => "[email protected] ", "SEEN"]);
133
+ * $query->where("FROM", "[email protected] ")->where("SEEN");
125
134
*/
126
135
public function where ($ criteria , $ value = null ) {
127
136
if (is_array ($ criteria )) {
128
137
foreach ($ criteria as $ key => $ value ) {
129
138
if (is_numeric ($ key )) {
130
- return $ this ->where ($ value );
139
+ $ this ->where ($ value );
140
+ }else {
141
+ $ this ->where ($ key , $ value );
131
142
}
132
- return $ this ->where ($ key , $ value );
133
143
}
134
144
} else {
135
- $ criteria = $ this ->validate_criteria ($ criteria );
136
- $ value = $ this ->parse_value ($ value );
137
-
138
- if ($ value === null || $ value === '' ) {
139
- $ this ->query ->push ([$ criteria ]);
140
- } else {
141
- $ this ->query ->push ([$ criteria , $ value ]);
142
- }
145
+ $ this ->push_search_criteria ($ criteria , $ value );
143
146
}
144
147
145
148
return $ this ;
146
149
}
147
150
151
+ /**
152
+ * Push a given search criteria and value pair to the search query
153
+ * @param $criteria string
154
+ * @param $value mixed
155
+ *
156
+ * @throws InvalidWhereQueryCriteriaException
157
+ */
158
+ protected function push_search_criteria ($ criteria , $ value ){
159
+ $ criteria = $ this ->validate_criteria ($ criteria );
160
+ $ value = $ this ->parse_value ($ value );
161
+
162
+ if ($ value === null || $ value === '' ) {
163
+ $ this ->query ->push ([$ criteria ]);
164
+ } else {
165
+ $ this ->query ->push ([$ criteria , $ value ]);
166
+ }
167
+ }
168
+
148
169
/**
149
170
* @param Closure $closure
150
171
*
@@ -468,8 +489,7 @@ public function whereLanguage($country_code) {
468
489
* @return WhereQuery
469
490
* @throws InvalidWhereQueryCriteriaException
470
491
*/
471
- public function whereUid ($ uid )
472
- {
492
+ public function whereUid ($ uid ) {
473
493
return $ this ->where ('UID ' , $ uid );
474
494
}
475
495
@@ -481,8 +501,7 @@ public function whereUid($uid)
481
501
* @return WhereQuery
482
502
* @throws InvalidWhereQueryCriteriaException
483
503
*/
484
- public function whereUidIn ($ uids )
485
- {
504
+ public function whereUidIn ($ uids ) {
486
505
$ uids = implode (', ' , $ uids );
487
506
return $ this ->where ('UID ' , $ uids );
488
507
}
@@ -491,10 +510,9 @@ public function whereUidIn($uids)
491
510
* Apply the callback if the given "value" is truthy.
492
511
* copied from @url https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Traits/Conditionable.php
493
512
*
494
- * @param mixed $value
495
- * @param callable $callback
496
- * @param callable|null $default
497
-
513
+ * @param mixed $value
514
+ * @param callable $callback
515
+ * @param callable|null $default
498
516
* @return $this|mixed
499
517
*/
500
518
public function when ($ value , $ callback , $ default = null ) {
@@ -511,14 +529,13 @@ public function when($value, $callback, $default = null) {
511
529
* Apply the callback if the given "value" is falsy.
512
530
* copied from @url https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Traits/Conditionable.php
513
531
*
514
- * @param mixed $value
515
- * @param callable $callback
516
- * @param callable|null $default
517
-
532
+ * @param mixed $value
533
+ * @param callable $callback
534
+ * @param callable|null $default
518
535
* @return $this|mixed
519
536
*/
520
537
public function unless ($ value , $ callback , $ default = null ) {
521
- if (! $ value ) {
538
+ if (!$ value ) {
522
539
return $ callback ($ this , $ value ) ?: $ this ;
523
540
} elseif ($ default ) {
524
541
return $ default ($ this , $ value ) ?: $ this ;
0 commit comments