Completed
Push — master ( 5649ba...c37d73 )
by recca
03:09
created

BuildsQueries::addWhereExistsQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Repository\Concerns;
4
5
use Closure;
6
use Recca0120\Repository\Method;
7
use Illuminate\Database\Query\Builder;
8
9
trait BuildsQueries
10
{
11
    /**
12
     * Set the columns to be selected.
13
     *
14
     * @param  array|mixed  $columns
15
     * @return $this
16
     */
17
    public function select($columns = ['*'])
18
    {
19
        $this->methods[] = new Method(__FUNCTION__, [$columns]);
0 ignored issues
show
Bug introduced by
The property methods does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
21
        return $this;
22
    }
23
24
    /**
25
     * Add a new "raw" select expression to the query.
26
     *
27
     * @param  string  $expression
28
     * @param  array   $bindings
29
     * @return $this
30
     */
31
    public function selectRaw($expression, array $bindings = [])
32
    {
33
        $this->methods[] = new Method(__FUNCTION__, [$expression, $bindings]);
34
35
        return $this;
36
    }
37
38
    /**
39
     * Add a subselect expression to the query.
40
     *
41
     * @param  \Closure|\Illuminate\Database\Query\Builder|string $query
42
     * @param  string  $as
43
     * @return $this
44
     *
45
     * @throws \InvalidArgumentException
46
     */
47
    public function selectSub($query, $as)
48
    {
49
        $this->methods[] = new Method(__FUNCTION__, [$query, $as]);
50
51
        return $this;
52
    }
53
54
    /**
55
     * Add a new select column to the query.
56
     *
57
     * @param  array|mixed  $column
58
     * @return $this
59
     */
60
    public function addSelect($column)
61
    {
62
        $this->methods[] = new Method(__FUNCTION__, [$column]);
63
64
        return $this;
65
    }
66
67
    /**
68
     * Force the query to only return distinct results.
69
     *
70
     * @return $this
71
     */
72
    public function distinct()
73
    {
74
        $this->methods[] = new Method(__FUNCTION__);
75
76
        return $this;
77
    }
78
79
    /**
80
     * Set the table which the query is targeting.
81
     *
82
     * @param  string  $table
83
     * @return $this
84
     */
85
    public function from($table)
86
    {
87
        $this->methods[] = new Method(__FUNCTION__, [$table]);
88
89
        return $this;
90
    }
91
92
    /**
93
     * Add a join clause to the query.
94
     *
95
     * @param  string  $table
96
     * @param  string  $first
97
     * @param  string  $operator
98
     * @param  string  $second
99
     * @param  string  $type
100
     * @param  bool    $where
101
     * @return $this
102
     */
103
    public function join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
104
    {
105
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second, $type, $where]);
106
107
        return $this;
108
    }
109
110
    /**
111
     * Add a "join where" clause to the query.
112
     *
113
     * @param  string  $table
114
     * @param  string  $first
115
     * @param  string  $operator
116
     * @param  string  $second
117
     * @param  string  $type
118
     * @return $this
119
     */
120
    public function joinWhere($table, $first, $operator, $second, $type = 'inner')
121
    {
122
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second, $type]);
123
124
        return $this;
125
    }
126
127
    /**
128
     * Add a left join to the query.
129
     *
130
     * @param  string  $table
131
     * @param  string  $first
132
     * @param  string  $operator
133
     * @param  string  $second
134
     * @return $this
135
     */
136
    public function leftJoin($table, $first, $operator = null, $second = null)
137
    {
138
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
139
140
        return $this;
141
    }
142
143
    /**
144
     * Add a "join where" clause to the query.
145
     *
146
     * @param  string  $table
147
     * @param  string  $first
148
     * @param  string  $operator
149
     * @param  string  $second
150
     * @return $this
151
     */
152
    public function leftJoinWhere($table, $first, $operator, $second)
153
    {
154
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
155
156
        return $this;
157
    }
158
159
    /**
160
     * Add a right join to the query.
161
     *
162
     * @param  string  $table
163
     * @param  string  $first
164
     * @param  string  $operator
165
     * @param  string  $second
166
     * @return $this
167
     */
168
    public function rightJoin($table, $first, $operator = null, $second = null)
169
    {
170
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
171
172
        return $this;
173
    }
174
175
    /**
176
     * Add a "right join where" clause to the query.
177
     *
178
     * @param  string  $table
179
     * @param  string  $first
180
     * @param  string  $operator
181
     * @param  string  $second
182
     * @return $this
183
     */
184
    public function rightJoinWhere($table, $first, $operator, $second)
185
    {
186
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
187
188
        return $this;
189
    }
190
191
    /**
192
     * Add a "cross join" clause to the query.
193
     *
194
     * @param  string  $table
195
     * @param  string  $first
196
     * @param  string  $operator
197
     * @param  string  $second
198
     * @return $this
199
     */
200
    public function crossJoin($table, $first = null, $operator = null, $second = null)
201
    {
202
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
203
204
        return $this;
205
    }
206
207
    /**
208
     * Merge an array of where clauses and bindings.
209
     *
210
     * @param  array  $wheres
211
     * @param  array  $bindings
212
     * @return void
213
     */
214
    public function mergeWheres($wheres, $bindings)
215
    {
216
        $this->methods[] = new Method(__FUNCTION__, [$wheres, $bindings]);
217
218
        return $this;
219
    }
220
221
    /**
222
     * Pass the query to a given callback.
223
     *
224
     * @param  \Closure  $callback
225
     * @return $this
226
     */
227
    public function tap($callback)
228
    {
229
        $this->methods[] = new Method(__FUNCTION__, [$callback]);
230
231
        return $this;
232
    }
233
234
    /**
235
     * Add a basic where clause to the query.
236
     *
237
     * @param  string|array|\Closure  $column
238
     * @param  string  $operator
239
     * @param  mixed   $value
240
     * @param  string  $boolean
241
     * @return $this
242
     */
243
    public function where($column, $operator = null, $value = null, $boolean = 'and')
244
    {
245
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
246
247
        return $this;
248
    }
249
250
    /**
251
     * Add an "or where" clause to the query.
252
     *
253
     * @param  \Closure|string  $column
254
     * @param  string  $operator
255
     * @param  mixed   $value
256
     * @return $this
257
     */
258
    public function orWhere($column, $operator = null, $value = null)
259
    {
260
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
261
262
        return $this;
263
    }
264
265
    /**
266
     * Add a "where" clause comparing two columns to the query.
267
     *
268
     * @param  string|array  $first
269
     * @param  string|null  $operator
270
     * @param  string|null  $second
271
     * @param  string|null  $boolean
272
     * @return $this
273
     */
274
    public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
275
    {
276
        $this->methods[] = new Method(__FUNCTION__, [$first, $operator, $second, $boolean]);
277
278
        return $this;
279
    }
280
281
    /**
282
     * Add an "or where" clause comparing two columns to the query.
283
     *
284
     * @param  string|array  $first
285
     * @param  string|null  $operator
286
     * @param  string|null  $second
287
     * @return $this
288
     */
289
    public function orWhereColumn($first, $operator = null, $second = null)
290
    {
291
        $this->methods[] = new Method(__FUNCTION__, [$first, $operator, $second]);
292
293
        return $this;
294
    }
295
296
    /**
297
     * Add a raw where clause to the query.
298
     *
299
     * @param  string  $sql
300
     * @param  mixed   $bindings
301
     * @param  string  $boolean
302
     * @return $this
303
     */
304
    public function whereRaw($sql, $bindings = [], $boolean = 'and')
305
    {
306
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings, $boolean]);
307
308
        return $this;
309
    }
310
311
    /**
312
     * Add a raw or where clause to the query.
313
     *
314
     * @param  string  $sql
315
     * @param  array   $bindings
316
     * @return $this
317
     */
318
    public function orWhereRaw($sql, array $bindings = [])
319
    {
320
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings]);
321
322
        return $this;
323
    }
324
325
    /**
326
     * Add a "where in" clause to the query.
327
     *
328
     * @param  string  $column
329
     * @param  mixed   $values
330
     * @param  string  $boolean
331
     * @param  bool    $not
332
     * @return $this
333
     */
334
    public function whereIn($column, $values, $boolean = 'and', $not = false)
335
    {
336
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean, $not]);
337
338
        return $this;
339
    }
340
341
    /**
342
     * Add an "or where in" clause to the query.
343
     *
344
     * @param  string  $column
345
     * @param  mixed   $values
346
     * @return $this
347
     */
348
    public function orWhereIn($column, $values)
349
    {
350
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
351
352
        return $this;
353
    }
354
355
    /**
356
     * Add a "where not in" clause to the query.
357
     *
358
     * @param  string  $column
359
     * @param  mixed   $values
360
     * @param  string  $boolean
361
     * @return $this
362
     */
363
    public function whereNotIn($column, $values, $boolean = 'and')
364
    {
365
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean]);
366
367
        return $this;
368
    }
369
370
    /**
371
     * Add an "or where not in" clause to the query.
372
     *
373
     * @param  string  $column
374
     * @param  mixed   $values
375
     * @return $this
376
     */
377
    public function orWhereNotIn($column, $values)
378
    {
379
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
380
381
        return $this;
382
    }
383
384
    /**
385
     * Add a "where null" clause to the query.
386
     *
387
     * @param  string  $column
388
     * @param  string  $boolean
389
     * @param  bool    $not
390
     * @return $this
391
     */
392
    public function whereNull($column, $boolean = 'and', $not = false)
393
    {
394
        $this->methods[] = new Method(__FUNCTION__, [$column, $boolean, $not]);
395
396
        return $this;
397
    }
398
399
    /**
400
     * Add an "or where null" clause to the query.
401
     *
402
     * @param  string  $column
403
     * @return $this
404
     */
405
    public function orWhereNull($column)
406
    {
407
        $this->methods[] = new Method(__FUNCTION__, [$column]);
408
409
        return $this;
410
    }
411
412
    /**
413
     * Add a "where not null" clause to the query.
414
     *
415
     * @param  string  $column
416
     * @param  string  $boolean
417
     * @return $this
418
     */
419
    public function whereNotNull($column, $boolean = 'and')
420
    {
421
        $this->methods[] = new Method(__FUNCTION__, [$column, $boolean]);
422
423
        return $this;
424
    }
425
426
    /**
427
     * Add a where between statement to the query.
428
     *
429
     * @param  string  $column
430
     * @param  array   $values
431
     * @param  string  $boolean
432
     * @param  bool  $not
433
     * @return $this
434
     */
435
    public function whereBetween($column, array $values, $boolean = 'and', $not = false)
436
    {
437
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean, $not]);
438
439
        return $this;
440
    }
441
442
    /**
443
     * Add an or where between statement to the query.
444
     *
445
     * @param  string  $column
446
     * @param  array   $values
447
     * @return $this
448
     */
449
    public function orWhereBetween($column, array $values)
450
    {
451
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
452
453
        return $this;
454
    }
455
456
    /**
457
     * Add a where not between statement to the query.
458
     *
459
     * @param  string  $column
460
     * @param  array   $values
461
     * @param  string  $boolean
462
     * @return $this
463
     */
464
    public function whereNotBetween($column, array $values, $boolean = 'and')
465
    {
466
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean]);
467
468
        return $this;
469
    }
470
471
    /**
472
     * Add an or where not between statement to the query.
473
     *
474
     * @param  string  $column
475
     * @param  array   $values
476
     * @return $this
477
     */
478
    public function orWhereNotBetween($column, array $values)
479
    {
480
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
481
482
        return $this;
483
    }
484
485
    /**
486
     * Add an "or where not null" clause to the query.
487
     *
488
     * @param  string  $column
489
     * @return $this
490
     */
491
    public function orWhereNotNull($column)
492
    {
493
        $this->methods[] = new Method(__FUNCTION__, [$column]);
494
495
        return $this;
496
    }
497
498
    /**
499
     * Add a "where date" statement to the query.
500
     *
501
     * @param  string  $column
502
     * @param  string  $operator
503
     * @param  mixed  $value
504
     * @param  string  $boolean
505
     * @return $this
506
     */
507
    public function whereDate($column, $operator, $value = null, $boolean = 'and')
508
    {
509
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
510
511
        return $this;
512
    }
513
514
    /**
515
     * Add an "or where date" statement to the query.
516
     *
517
     * @param  string  $column
518
     * @param  string  $operator
519
     * @param  string  $value
520
     * @return $this
521
     */
522
    public function orWhereDate($column, $operator, $value)
523
    {
524
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
525
526
        return $this;
527
    }
528
529
    /**
530
     * Add a "where time" statement to the query.
531
     *
532
     * @param  string  $column
533
     * @param  string   $operator
534
     * @param  int   $value
535
     * @param  string   $boolean
536
     * @return $this
537
     */
538
    public function whereTime($column, $operator, $value, $boolean = 'and')
539
    {
540
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
541
542
        return $this;
543
    }
544
545
    /**
546
     * Add an "or where time" statement to the query.
547
     *
548
     * @param  string  $column
549
     * @param  string   $operator
550
     * @param  int   $value
551
     * @return $this
552
     */
553
    public function orWhereTime($column, $operator, $value)
554
    {
555
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
556
557
        return $this;
558
    }
559
560
    /**
561
     * Add a "where day" statement to the query.
562
     *
563
     * @param  string  $column
564
     * @param  string  $operator
565
     * @param  mixed  $value
566
     * @param  string  $boolean
567
     * @return $this
568
     */
569
    public function whereDay($column, $operator, $value = null, $boolean = 'and')
570
    {
571
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
572
573
        return $this;
574
    }
575
576
    /**
577
     * Add a "where month" statement to the query.
578
     *
579
     * @param  string  $column
580
     * @param  string  $operator
581
     * @param  mixed  $value
582
     * @param  string  $boolean
583
     * @return $this
584
     */
585
    public function whereMonth($column, $operator, $value = null, $boolean = 'and')
586
    {
587
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
588
589
        return $this;
590
    }
591
592
    /**
593
     * Add a "where year" statement to the query.
594
     *
595
     * @param  string  $column
596
     * @param  string  $operator
597
     * @param  mixed  $value
598
     * @param  string  $boolean
599
     * @return $this
600
     */
601
    public function whereYear($column, $operator, $value = null, $boolean = 'and')
602
    {
603
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
604
605
        return $this;
606
    }
607
608
    /**
609
     * Add a nested where statement to the query.
610
     *
611
     * @param  \Closure $callback
612
     * @param  string   $boolean
613
     * @return $this
614
     */
615
    public function whereNested(Closure $callback, $boolean = 'and')
616
    {
617
        $this->methods[] = new Method(__FUNCTION__, [$callback, $boolean]);
618
619
        return $this;
620
    }
621
622
    /**
623
     * Add another query builder as a nested where to the query builder.
624
     *
625
     * @param  $this $query
0 ignored issues
show
introduced by
The type BuildsQueries for parameter $query is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
626
     * @param  string  $boolean
627
     * @return $this
628
     */
629
    public function addNestedWhereQuery($query, $boolean = 'and')
630
    {
631
        $this->methods[] = new Method(__FUNCTION__, [$query, $boolean]);
632
633
        return $this;
634
    }
635
636
    /**
637
     * Add an exists clause to the query.
638
     *
639
     * @param  \Closure $callback
640
     * @param  string   $boolean
641
     * @param  bool     $not
642
     * @return $this
643
     */
644
    public function whereExists(Closure $callback, $boolean = 'and', $not = false)
645
    {
646
        $this->methods[] = new Method(__FUNCTION__, [$callback, $boolean, $not]);
647
648
        return $this;
649
    }
650
651
    /**
652
     * Add an or exists clause to the query.
653
     *
654
     * @param  \Closure $callback
655
     * @param  bool     $not
656
     * @return $this
657
     */
658
    public function orWhereExists(Closure $callback, $not = false)
659
    {
660
        $this->methods[] = new Method(__FUNCTION__, [$callback, $not]);
661
662
        return $this;
663
    }
664
665
    /**
666
     * Add a where not exists clause to the query.
667
     *
668
     * @param  \Closure $callback
669
     * @param  string   $boolean
670
     * @return $this
671
     */
672
    public function whereNotExists(Closure $callback, $boolean = 'and')
673
    {
674
        $this->methods[] = new Method(__FUNCTION__, [$callback, $boolean]);
675
676
        return $this;
677
    }
678
679
    /**
680
     * Add a where not exists clause to the query.
681
     *
682
     * @param  \Closure  $callback
683
     * @return $this
684
     */
685
    public function orWhereNotExists(Closure $callback)
686
    {
687
        $this->methods[] = new Method(__FUNCTION__, [$callback]);
688
689
        return $this;
690
    }
691
692
    /**
693
     * Add an exists clause to the query.
694
     *
695
     * @param  \Illuminate\Database\Query\Builder $query
696
     * @param  string  $boolean
697
     * @param  bool  $not
698
     * @return $this
699
     */
700
    public function addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false)
701
    {
702
        $this->methods[] = new Method(__FUNCTION__, [$query, $boolean, $not]);
703
704
        return $this;
705
    }
706
707
    /**
708
     * Handles dynamic "where" clauses to the query.
709
     *
710
     * @param  string  $method
711
     * @param  string  $parameters
712
     * @return $this
713
     */
714
    public function dynamicWhere($method, $parameters)
715
    {
716
        $this->methods[] = new Method(__FUNCTION__, [$method, $parameters]);
717
718
        return $this;
719
    }
720
721
    /**
722
     * Add a "group by" clause to the query.
723
     *
724
     * @param  array  ...$groups
725
     * @return $this
726
     */
727
    public function groupBy()
728
    {
729
        $this->methods[] = new Method(__FUNCTION__, func_get_args());
730
731
        return $this;
732
    }
733
734
    /**
735
     * Add a "having" clause to the query.
736
     *
737
     * @param  string  $column
738
     * @param  string  $operator
739
     * @param  string  $value
740
     * @param  string  $boolean
741
     * @return $this
742
     */
743
    public function having($column, $operator = null, $value = null, $boolean = 'and')
744
    {
745
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
746
747
        return $this;
748
    }
749
750
    /**
751
     * Add a "or having" clause to the query.
752
     *
753
     * @param  string  $column
754
     * @param  string  $operator
755
     * @param  string  $value
756
     * @return $this
757
     */
758
    public function orHaving($column, $operator = null, $value = null)
759
    {
760
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
761
762
        return $this;
763
    }
764
765
    /**
766
     * Add a raw having clause to the query.
767
     *
768
     * @param  string  $sql
769
     * @param  array   $bindings
770
     * @param  string  $boolean
771
     * @return $this
772
     */
773
    public function havingRaw($sql, array $bindings = [], $boolean = 'and')
774
    {
775
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings, $boolean]);
776
777
        return $this;
778
    }
779
780
    /**
781
     * Add a raw or having clause to the query.
782
     *
783
     * @param  string  $sql
784
     * @param  array   $bindings
785
     * @return $this
786
     */
787
    public function orHavingRaw($sql, array $bindings = [])
788
    {
789
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings]);
790
791
        return $this;
792
    }
793
794
    /**
795
     * Add an "order by" clause to the query.
796
     *
797
     * @param  string  $column
798
     * @param  string  $direction
799
     * @return $this
800
     */
801
    public function orderBy($column, $direction = 'asc')
802
    {
803
        $this->methods[] = new Method(__FUNCTION__, [$column, $direction]);
804
805
        return $this;
806
    }
807
808
    /**
809
     * Add a descending "order by" clause to the query.
810
     *
811
     * @param  string  $column
812
     * @return $this
813
     */
814
    public function orderByDesc($column)
815
    {
816
        $this->methods[] = new Method(__FUNCTION__, [$column]);
817
818
        return $this;
819
    }
820
821
    /**
822
     * Add an "order by" clause for a timestamp to the query.
823
     *
824
     * @param  string  $column
825
     * @return $this
826
     */
827
    public function latest($column = 'created_at')
828
    {
829
        $this->methods[] = new Method(__FUNCTION__, [$column]);
830
831
        return $this;
832
    }
833
834
    /**
835
     * Add an "order by" clause for a timestamp to the query.
836
     *
837
     * @param  string  $column
838
     * @return $this
839
     */
840
    public function oldest($column = 'created_at')
841
    {
842
        $this->methods[] = new Method(__FUNCTION__, [$column]);
843
844
        return $this;
845
    }
846
847
    /**
848
     * Put the query's results in random order.
849
     *
850
     * @param  string  $seed
851
     * @return $this
852
     */
853
    public function inRandomOrder($seed = '')
854
    {
855
        $this->methods[] = new Method(__FUNCTION__, [$seed]);
856
857
        return $this;
858
    }
859
860
    /**
861
     * Add a raw "order by" clause to the query.
862
     *
863
     * @param  string  $sql
864
     * @param  array  $bindings
865
     * @return $this
866
     */
867
    public function orderByRaw($sql, $bindings = [])
868
    {
869
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings]);
870
871
        return $this;
872
    }
873
874
    /**
875
     * Alias to set the "offset" value of the query.
876
     *
877
     * @param  int  $value
878
     * @return $this
879
     */
880
    public function skip($value)
881
    {
882
        $this->methods[] = new Method(__FUNCTION__, [$value]);
883
884
        return $this;
885
    }
886
887
    /**
888
     * Set the "offset" value of the query.
889
     *
890
     * @param  int  $value
891
     * @return $this
892
     */
893
    public function offset($value)
894
    {
895
        $this->methods[] = new Method(__FUNCTION__, [$value]);
896
897
        return $this;
898
    }
899
900
    /**
901
     * Alias to set the "limit" value of the query.
902
     *
903
     * @param  int  $value
904
     * @return $this
905
     */
906
    public function take($value)
907
    {
908
        $this->methods[] = new Method(__FUNCTION__, [$value]);
909
910
        return $this;
911
    }
912
913
    /**
914
     * Set the "limit" value of the query.
915
     *
916
     * @param  int  $value
917
     * @return $this
918
     */
919
    public function limit($value)
920
    {
921
        $this->methods[] = new Method(__FUNCTION__, [$value]);
922
923
        return $this;
924
    }
925
926
    /**
927
     * Set the limit and offset for a given page.
928
     *
929
     * @param  int  $page
930
     * @param  int  $perPage
931
     * @return $this
932
     */
933
    public function forPage($page, $perPage = 15)
934
    {
935
        $this->methods[] = new Method(__FUNCTION__, [$page, $perPage]);
936
937
        return $this;
938
    }
939
940
    /**
941
     * Constrain the query to the next "page" of results after a given ID.
942
     *
943
     * @param  int  $perPage
944
     * @param  int  $lastId
945
     * @param  string  $column
946
     * @return $this
947
     */
948
    public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
949
    {
950
        $this->methods[] = new Method(__FUNCTION__, [$perPage, $lastId, $column]);
951
952
        return $this;
953
    }
954
955
    /**
956
     * Add a union statement to the query.
957
     *
958
     * @param  \Illuminate\Database\Query\Builder|\Closure  $query
959
     * @param  bool  $all
960
     * @return $this
961
     */
962
    public function union($query, $all = false)
963
    {
964
        $this->methods[] = new Method(__FUNCTION__, [$query, $all]);
965
966
        return $this;
967
    }
968
969
    /**
970
     * Add a union all statement to the query.
971
     *
972
     * @param  \Illuminate\Database\Query\Builder|\Closure  $query
973
     * @return $this
974
     */
975
    public function unionAll($query)
976
    {
977
        $this->methods[] = new Method(__FUNCTION__, [$query]);
978
979
        return $this;
980
    }
981
982
    /**
983
     * Lock the selected rows in the table.
984
     *
985
     * @param  string|bool  $value
986
     * @return $this
987
     */
988
    public function lock($value = true)
989
    {
990
        $this->methods[] = new Method(__FUNCTION__, [$value]);
991
992
        return $this;
993
    }
994
995
    /**
996
     * Lock the selected rows in the table for updating.
997
     *
998
     * @return $this
999
     */
1000
    public function lockForUpdate()
1001
    {
1002
        $this->methods[] = new Method(__FUNCTION__);
1003
1004
        return $this;
1005
    }
1006
1007
    /**
1008
     * Share lock the selected rows in the table.
1009
     *
1010
     * @return $this
1011
     */
1012
    public function sharedLock()
1013
    {
1014
        $this->methods[] = new Method(__FUNCTION__);
1015
1016
        return $this;
1017
    }
1018
1019
    /**
1020
     * Apply the callback's query changes if the given "value" is true.
1021
     *
1022
     * @param  mixed  $value
1023
     * @param  callable  $callback
1024
     * @param  callable  $default
1025
     * @return $this
1026
     */
1027
    public function when($value, $callback, $default = null)
1028
    {
1029
        $this->methods[] = new Method(__FUNCTION__, [$value, $callback, $default]);
1030
1031
        return $this;
1032
    }
1033
1034
    /**
1035
     * Apply the callback's query changes if the given "value" is false.
1036
     *
1037
     * @param  mixed  $value
1038
     * @param  callable  $callback
1039
     * @param  callable  $default
1040
     * @return $this
1041
     */
1042
    public function unless($value, $callback, $default = null)
1043
    {
1044
        $this->methods[] = new Method(__FUNCTION__, [$value, $callback, $default]);
1045
1046
        return $this;
1047
    }
1048
}
1049