1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NwLaravel\Repositories\Eloquent; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
use Prettus\Repository\Eloquent\BaseRepository; |
7
|
|
|
use NwLaravel\Repositories\RepositoryInterface; |
8
|
|
|
use NwLaravel\Repositories\Criterias\InputCriteria; |
9
|
|
|
use NwLaravel\Resultset\BuilderResultset; |
10
|
|
|
use Prettus\Validator\Contracts\ValidatorInterface; |
11
|
|
|
use Prettus\Repository\Events\RepositoryEntityCreated; |
12
|
|
|
use Prettus\Repository\Events\RepositoryEntityUpdated; |
13
|
|
|
use Prettus\Repository\Events\RepositoryEntityDeleted; |
14
|
|
|
use Illuminate\Database\Query\Expression; |
15
|
|
|
use Illuminate\Database\Query\Grammars; |
16
|
|
|
use BadMethodCallException; |
17
|
|
|
use RuntimeException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class AbstractRepository |
21
|
|
|
* |
22
|
|
|
* @abstract |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractRepository extends BaseRepository implements RepositoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $orderBy; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $skipPresenter = true; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return Model |
38
|
|
|
* @throws RepositoryException |
39
|
|
|
*/ |
40
|
29 |
|
public function makeModel() |
41
|
|
|
{ |
42
|
29 |
|
parent::makeModel(); |
43
|
29 |
|
return $this->model = $this->model->newQuery(); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Reset Model |
48
|
|
|
* |
49
|
|
|
* @return AbstractRepository |
50
|
|
|
* @throws RepositoryException |
51
|
|
|
*/ |
52
|
12 |
|
public function resetModel() |
53
|
|
|
{ |
54
|
12 |
|
parent::resetModel(); |
55
|
12 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get Query |
60
|
|
|
* |
61
|
|
|
* @return Builder |
62
|
|
|
*/ |
63
|
8 |
|
public function getQuery() |
64
|
|
|
{ |
65
|
8 |
|
$this->applyCriteria(); |
66
|
8 |
|
$this->applyScope(); |
67
|
|
|
|
68
|
8 |
|
$model = $this->model; |
69
|
|
|
|
70
|
8 |
|
$this->resetModel(); |
71
|
8 |
|
return $model; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Search All |
76
|
|
|
* |
77
|
|
|
* @param array $input Array Imput |
78
|
|
|
* @param string $orderBy String Order By |
79
|
|
|
* @param int $limit Integer Limit |
80
|
|
|
* @param bool $skipPresenter Boolean Skip Presenter |
81
|
|
|
* |
82
|
|
|
* @return BuilderResultset |
83
|
|
|
*/ |
84
|
1 |
|
public function searchAll(array $input, $orderBy = '', $limit = null, $skipPresenter = true) |
85
|
|
|
{ |
86
|
1 |
|
$orderBy = $orderBy?:$this->orderBy; |
87
|
|
|
|
88
|
1 |
|
$query = $this |
89
|
1 |
|
->whereInputCriteria($input) |
90
|
1 |
|
->orderBy($orderBy) |
91
|
1 |
|
->skipPresenter($skipPresenter) |
92
|
1 |
|
->getQuery() |
93
|
1 |
|
->limit($limit); |
94
|
|
|
|
95
|
1 |
|
return new BuilderResultset($query); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Search Paginator |
100
|
|
|
* |
101
|
|
|
* @param array $input Array Input |
102
|
|
|
* @param string $orderBy String Order By |
103
|
|
|
* @param int|null $limit Integer Limit |
104
|
|
|
* @param bool $skipPresenter Boolean Skip Presenter |
105
|
|
|
* |
106
|
|
|
* @return Paginator |
107
|
|
|
*/ |
108
|
1 |
|
public function search(array $input, $orderBy = '', $limit = null, $skipPresenter = true) |
109
|
|
|
{ |
110
|
1 |
|
$orderBy = $orderBy?:$this->orderBy; |
111
|
|
|
|
112
|
1 |
|
return $this |
113
|
1 |
|
->whereInputCriteria($input) |
114
|
1 |
|
->orderBy($orderBy) |
115
|
1 |
|
->skipPresenter($skipPresenter) |
116
|
1 |
|
->paginate($limit); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* ResultSet |
121
|
|
|
* |
122
|
|
|
* @param int $limit Integer Limit |
123
|
|
|
* |
124
|
|
|
* @return BuilderResultset |
125
|
|
|
*/ |
126
|
|
|
public function resultset($limit = null) |
127
|
|
|
{ |
128
|
|
|
$query = $this->getQuery()->limit($limit); |
129
|
|
|
|
130
|
|
|
return new BuilderResultset($query); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get an array with the values of a given column. |
135
|
|
|
* |
136
|
|
|
* @param string $column String Column |
137
|
|
|
* @param string $key String Key |
138
|
|
|
* |
139
|
|
|
* @return \Illuminate\Support\Collection |
140
|
|
|
*/ |
141
|
1 |
|
public function pluck($column, $key = null) |
142
|
|
|
{ |
143
|
1 |
|
return $this->getQuery()->pluck($column, $key); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Add an "order by" clause to the query. |
148
|
|
|
* |
149
|
|
|
* @param string $columns String Columns |
150
|
|
|
* @param string $direction String Direction |
151
|
|
|
* |
152
|
|
|
* @return RepositoryInterface |
153
|
|
|
*/ |
154
|
3 |
|
public function orderBy($columns, $direction = 'asc') |
155
|
|
|
{ |
156
|
3 |
|
if (!empty($columns)) { |
157
|
3 |
|
$columns = explode(',', $columns); |
158
|
3 |
|
foreach ($columns as $key => $column) { |
159
|
3 |
|
$column = explode(' ', $column); |
160
|
3 |
|
$column = array_filter($column); |
161
|
3 |
|
$column = array_pad($column, 2, ''); |
162
|
3 |
|
list($field, $sort) = array_values($column); |
163
|
3 |
|
if (!empty($sort)) { |
164
|
2 |
|
$direction = $sort; |
165
|
2 |
|
} |
166
|
3 |
|
$direction = strtoupper($direction); |
167
|
3 |
|
$direction = in_array($direction, ['ASC', 'DESC']) ? $direction : 'ASC'; |
168
|
3 |
|
$this->model = $this->model->orderBy($field, $direction); |
169
|
3 |
|
} |
170
|
3 |
|
} |
171
|
|
|
|
172
|
3 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Random |
177
|
|
|
* |
178
|
|
|
* @return RepositoryInterface |
179
|
|
|
*/ |
180
|
4 |
|
public function random() |
181
|
|
|
{ |
182
|
4 |
|
$grammar = $this->model->getConnection()->getQueryGrammar(); |
183
|
|
|
|
184
|
4 |
|
switch (true) { |
185
|
4 |
|
case $grammar instanceof Grammars\MySqlGrammar: |
186
|
4 |
|
case $grammar instanceof Grammars\SqlServerGrammar: |
187
|
2 |
|
$random = 'RAND()'; |
188
|
2 |
|
break; |
189
|
2 |
|
case $grammar instanceof Grammars\PostgresGrammar: |
190
|
2 |
|
case $grammar instanceof Grammars\SQLiteGrammar: |
191
|
2 |
|
$random = 'RANDOM()'; |
192
|
2 |
|
} |
193
|
|
|
|
194
|
4 |
|
$this->model = $this->model->orderBy(new Expression($random)); |
|
|
|
|
195
|
|
|
|
196
|
4 |
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Count results of repository |
201
|
|
|
* |
202
|
|
|
* @param array $where |
203
|
|
|
* @param string $columns |
204
|
|
|
* |
205
|
|
|
* @return int |
206
|
|
|
*/ |
207
|
1 |
|
public function count(array $where = [], $columns = '*') |
208
|
|
|
{ |
209
|
1 |
|
$this->whereInputCriteria($where); |
210
|
|
|
|
211
|
1 |
|
return $this->getQuery()->count($columns); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Max |
216
|
|
|
* |
217
|
|
|
* @param mixed $field Mixed Field |
218
|
|
|
* @param array $input Array Input |
219
|
|
|
* |
220
|
|
|
* @return mixed |
221
|
|
|
*/ |
222
|
1 |
|
public function max($field, array $input = array()) |
223
|
|
|
{ |
224
|
1 |
|
$this->whereInputCriteria($input); |
225
|
|
|
|
226
|
1 |
|
return $this->getQuery()->max($field); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Min |
231
|
|
|
* |
232
|
|
|
* @param mixed $field Mixed Field |
233
|
|
|
* @param array $input Array Input |
234
|
|
|
* |
235
|
|
|
* @return mixed |
236
|
|
|
*/ |
237
|
1 |
|
public function min($field, array $input = array()) |
238
|
|
|
{ |
239
|
1 |
|
$this->whereInputCriteria($input); |
240
|
|
|
|
241
|
1 |
|
return $this->getQuery()->min($field); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Sum |
246
|
|
|
* |
247
|
|
|
* @param mixed $field Mixed Field |
248
|
|
|
* @param array $input Array Input |
249
|
|
|
* |
250
|
|
|
* @return float |
251
|
|
|
*/ |
252
|
1 |
|
public function sum($field, array $input = array()) |
253
|
|
|
{ |
254
|
1 |
|
$this->whereInputCriteria($input); |
255
|
|
|
|
256
|
1 |
|
return $this->getQuery()->sum($field); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Average |
261
|
|
|
* |
262
|
|
|
* @param mixed $field Mixed Field |
263
|
|
|
* @param array $input Array Input |
264
|
|
|
* |
265
|
|
|
* @return int |
266
|
|
|
*/ |
267
|
1 |
|
public function avg($field, array $input = array()) |
268
|
|
|
{ |
269
|
1 |
|
$this->whereInputCriteria($input); |
270
|
|
|
|
271
|
1 |
|
return $this->getQuery()->avg($field); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Order Up |
276
|
|
|
* |
277
|
|
|
* @param Model $model |
278
|
|
|
* @param string $field Field Order |
279
|
|
|
* @param array $input Array Where |
280
|
|
|
* |
281
|
|
|
* @return boolean |
282
|
|
|
*/ |
283
|
|
|
public function orderUp($model, $field, array $input = []) |
284
|
|
|
{ |
285
|
|
|
$input["{$field} <= ?"] = $model->{$field}; |
286
|
|
|
$input["id != ?"] = $model->id; |
287
|
|
|
return $this->reorder($model, $field, $input, 'DESC'); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Order Top |
292
|
|
|
* |
293
|
|
|
* @param Model $model |
294
|
|
|
* @param string $field Field Order |
295
|
|
|
* @param array $input Array Where |
296
|
|
|
* |
297
|
|
|
* @return boolean |
298
|
|
|
*/ |
299
|
|
|
public function orderTop($model, $field, array $input = []) |
300
|
|
|
{ |
301
|
|
|
return $this->reorder($model, $field, $input, 'ASC'); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Order Down |
306
|
|
|
* |
307
|
|
|
* @param Model $model |
308
|
|
|
* @param string $field Field Order |
309
|
|
|
* @param array $input Array Where |
310
|
|
|
* |
311
|
|
|
* @return boolean |
312
|
|
|
*/ |
313
|
|
|
public function orderDown($model, $field, array $input = []) |
314
|
|
|
{ |
315
|
|
|
$input["{$field} >= ?"] = $model->{$field}; |
316
|
|
|
$input["id != ?"] = $model->id; |
317
|
|
|
return $this->reorder($model, $field, $input, 'ASC'); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Order Bottom |
322
|
|
|
* |
323
|
|
|
* @param Model $model |
324
|
|
|
* @param string $field Field Order |
325
|
|
|
* @param array $input Array Where |
326
|
|
|
* |
327
|
|
|
* @return boolean |
328
|
|
|
*/ |
329
|
|
|
public function orderBottom($model, $field, array $input = []) |
330
|
|
|
{ |
331
|
|
|
return $this->reorder($model, $field, $input, 'DESC'); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Reorder |
336
|
|
|
* |
337
|
|
|
* @param Model $model |
338
|
|
|
* @param string $field Field Order |
339
|
|
|
* @param array $input Array Where |
340
|
|
|
* @param string $sort Sort |
341
|
|
|
* |
342
|
|
|
* @return boolean |
343
|
|
|
*/ |
344
|
|
|
protected function reorder($model, $field, array $input, $sort) |
345
|
|
|
{ |
346
|
|
|
if (!$model->exists) { |
347
|
|
|
return false; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
$order = $model->{$field}; |
351
|
|
|
|
352
|
|
|
$anterior = $this->whereInputCriteria($input)->orderBy($field, $sort)->first(); |
353
|
|
|
|
354
|
|
|
if ($anterior) { |
355
|
|
|
$model->{$field} = $anterior->{$field}; |
356
|
|
|
$model->save(); |
357
|
|
|
|
358
|
|
|
$anterior->{$field} = $order; |
359
|
|
|
$anterior->save(); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
event(new RepositoryEntityUpdated($this, $model)); |
363
|
|
|
|
364
|
|
|
return true; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Where InputCriteria |
369
|
|
|
* |
370
|
|
|
* @param array $input Array Input |
371
|
|
|
* |
372
|
|
|
* @return RepositoryInterface |
373
|
|
|
*/ |
374
|
7 |
|
public function whereInputCriteria(array $input = array()) |
375
|
|
|
{ |
376
|
7 |
|
if (count($input)) { |
377
|
6 |
|
$criteria = new InputCriteria($input); |
378
|
6 |
|
$this->model = $criteria->apply($this->model, $this); |
|
|
|
|
379
|
6 |
|
} |
380
|
|
|
|
381
|
7 |
|
return $this; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* Validar |
386
|
|
|
* |
387
|
|
|
* @param array $attributes |
388
|
|
|
* @param string $action |
389
|
|
|
* @param string $id |
390
|
|
|
* |
391
|
|
|
* @return bool |
392
|
|
|
*/ |
393
|
2 |
|
public function validar(array $attributes, $action, $id = null) |
394
|
|
|
{ |
395
|
2 |
|
$return = false; |
396
|
|
|
|
397
|
2 |
|
if (!is_null($this->validator)) { |
398
|
|
|
// we should pass data that has been casts by the model |
399
|
|
|
// to make sure data type are same because validator may need to use |
400
|
|
|
// this data to compare with data that fetch from database. |
401
|
2 |
|
$model = $this->model->newModelInstance()->fill($attributes); |
402
|
2 |
|
$attributes = array_merge($attributes, $model->toArray()); |
403
|
|
|
|
404
|
2 |
|
$validator = $this->validator->with($attributes); |
405
|
|
|
|
406
|
2 |
|
if ($id) { |
|
|
|
|
407
|
1 |
|
$validator->setId($id); |
408
|
1 |
|
} |
409
|
|
|
|
410
|
2 |
|
$return = $validator->passesOrFail($action); |
411
|
2 |
|
} |
412
|
|
|
|
413
|
2 |
|
return $return; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Save a new model in repository |
418
|
|
|
* |
419
|
|
|
* @throws ValidatorException |
420
|
|
|
* @param array $attributes Array Attributes |
421
|
|
|
* @return mixed |
422
|
|
|
*/ |
423
|
1 |
|
public function create(array $attributes) |
424
|
|
|
{ |
425
|
1 |
|
$this->validar($attributes, ValidatorInterface::RULE_CREATE); |
426
|
|
|
|
427
|
1 |
|
$model = $this->model->newModelInstance($attributes); |
428
|
1 |
|
$model->save(); |
429
|
1 |
|
$this->resetModel(); |
430
|
|
|
|
431
|
1 |
|
event(new RepositoryEntityCreated($this, $model)); |
432
|
|
|
|
433
|
1 |
|
return $this->parserResult($model); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Update a model in repository by id |
438
|
|
|
* |
439
|
|
|
* @throws ValidatorException |
440
|
|
|
* @param array $attributes Array Attributes |
441
|
|
|
* @param int $id Integer Id |
442
|
|
|
* @return mixed |
443
|
|
|
*/ |
444
|
1 |
|
public function update(array $attributes, $id) |
445
|
|
|
{ |
446
|
1 |
|
$this->applyScope(); |
447
|
|
|
|
448
|
1 |
|
$this->validar($attributes, ValidatorInterface::RULE_UPDATE, $id); |
449
|
|
|
|
450
|
1 |
|
$temporarySkipPresenter = $this->skipPresenter; |
451
|
|
|
|
452
|
1 |
|
$this->skipPresenter(true); |
453
|
|
|
|
454
|
1 |
|
$model = $this->model->findOrFail($id); |
455
|
1 |
|
$model->fill($attributes); |
456
|
1 |
|
$model->save(); |
457
|
|
|
|
458
|
1 |
|
$this->skipPresenter($temporarySkipPresenter); |
459
|
1 |
|
$this->resetModel(); |
460
|
|
|
|
461
|
1 |
|
event(new RepositoryEntityUpdated($this, $model)); |
462
|
|
|
|
463
|
1 |
|
return $this->parserResult($model); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Delete Force a entity in repository by id |
468
|
|
|
* |
469
|
|
|
* @param $id |
470
|
|
|
* |
471
|
|
|
* @return int |
472
|
|
|
*/ |
473
|
|
|
public function deleteForce($id) |
474
|
|
|
{ |
475
|
|
|
$this->applyScope(); |
476
|
|
|
|
477
|
|
|
$temporarySkipPresenter = $this->skipPresenter; |
478
|
|
|
$this->skipPresenter(true); |
479
|
|
|
|
480
|
|
|
$model = $this->find($id); |
481
|
|
|
$originalModel = clone $model; |
482
|
|
|
|
483
|
|
|
$this->skipPresenter($temporarySkipPresenter); |
484
|
|
|
$this->resetModel(); |
485
|
|
|
|
486
|
|
|
$deleted = $model->forceDelete(); |
487
|
|
|
|
488
|
|
|
event(new RepositoryEntityDeleted($this, $originalModel)); |
489
|
|
|
|
490
|
|
|
return $deleted; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Delete multiple entities by given criteria. |
495
|
|
|
* |
496
|
|
|
* @param array $where |
497
|
|
|
* |
498
|
|
|
* @return boolean|null |
499
|
|
|
*/ |
500
|
1 |
|
public function deleteWhere(array $where) |
501
|
|
|
{ |
502
|
1 |
|
$this->applyCriteria(); |
503
|
1 |
|
$this->applyScope(); |
504
|
|
|
|
505
|
1 |
|
$temporarySkipPresenter = $this->skipPresenter; |
506
|
1 |
|
$this->skipPresenter(true); |
507
|
|
|
|
508
|
1 |
|
$this->whereInputCriteria($where); |
509
|
|
|
|
510
|
1 |
|
$deleted = $this->model->delete(); |
511
|
|
|
|
512
|
1 |
|
$model = $this->model instanceof Builder ? $this->model->getModel() : $this->model; |
513
|
1 |
|
event(new RepositoryEntityDeleted($this, $model)); |
514
|
|
|
|
515
|
1 |
|
$this->skipPresenter($temporarySkipPresenter); |
516
|
1 |
|
$this->resetModel(); |
517
|
|
|
|
518
|
1 |
|
return $deleted; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* Update multiple entities by given criteria. |
523
|
|
|
* |
524
|
|
|
* @param array $where |
525
|
|
|
* |
526
|
|
|
* @return boolean|null |
527
|
|
|
*/ |
528
|
1 |
|
public function updateWhere(array $attributes, array $where) |
529
|
|
|
{ |
530
|
1 |
|
$this->applyCriteria(); |
531
|
1 |
|
$this->applyScope(); |
532
|
|
|
|
533
|
1 |
|
$temporarySkipPresenter = $this->skipPresenter; |
534
|
1 |
|
$this->skipPresenter(true); |
535
|
|
|
|
536
|
1 |
|
$this->whereInputCriteria($where); |
537
|
|
|
|
538
|
1 |
|
$updated = $this->model->update($attributes); |
539
|
|
|
|
540
|
1 |
|
$this->skipPresenter($temporarySkipPresenter); |
541
|
1 |
|
$this->resetModel(); |
542
|
|
|
|
543
|
1 |
|
$model = $this->model instanceof Builder ? $this->model->getModel() : $this->model; |
544
|
1 |
|
event(new RepositoryEntityUpdated($this, $model)); |
545
|
|
|
|
546
|
1 |
|
return $updated; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Add a subquery join clause to the query. |
551
|
|
|
* |
552
|
|
|
* @param \Closure|\Illuminate\Database\Query\Builder|string $query |
553
|
|
|
* @param string $as |
554
|
|
|
* @param string $first |
555
|
|
|
* @param string|null $operator |
556
|
|
|
* @param string|null $second |
557
|
|
|
* @param string $type |
558
|
|
|
* @param bool $where |
559
|
|
|
* @return \Illuminate\Database\Query\Builder|static |
560
|
|
|
* |
561
|
|
|
* @throws \InvalidArgumentException |
562
|
|
|
*/ |
563
|
|
|
public function joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false) |
564
|
|
|
{ |
565
|
|
|
$sql = $query->toSql(); |
|
|
|
|
566
|
|
|
$bindings = $query->getBindings(); |
|
|
|
|
567
|
|
|
$expression = '('.$sql.') as '.$this->model->getGrammar()->wrap($as); |
568
|
|
|
$this->model->addBinding($bindings, 'join'); |
569
|
|
|
|
570
|
|
|
return $this->join(new Expression($expression), $first, $operator, $second, $type, $where); |
|
|
|
|
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* Add a subquery left join to the query. |
575
|
|
|
* |
576
|
|
|
* @param \Closure|\Illuminate\Database\Query\Builder|string $query |
577
|
|
|
* @param string $as |
578
|
|
|
* @param string $first |
579
|
|
|
* @param string|null $operator |
580
|
|
|
* @param string|null $second |
581
|
|
|
* @return \Illuminate\Database\Query\Builder|static |
582
|
|
|
*/ |
583
|
|
|
public function leftJoinSub($query, $as, $first, $operator = null, $second = null) |
584
|
|
|
{ |
585
|
|
|
return $this->joinSub($query, $as, $first, $operator, $second, 'left'); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Add a subquery right join to the query. |
590
|
|
|
* |
591
|
|
|
* @param \Closure|\Illuminate\Database\Query\Builder|string $query |
592
|
|
|
* @param string $as |
593
|
|
|
* @param string $first |
594
|
|
|
* @param string|null $operator |
595
|
|
|
* @param string|null $second |
596
|
|
|
* @return \Illuminate\Database\Query\Builder|static |
597
|
|
|
*/ |
598
|
|
|
public function rightJoinSub($query, $as, $first, $operator = null, $second = null) |
599
|
|
|
{ |
600
|
|
|
return $this->joinSub($query, $as, $first, $operator, $second, 'right'); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Handle dynamic method calls into the method. |
605
|
|
|
* |
606
|
|
|
* @param string $method |
607
|
|
|
* @param array $parameters |
608
|
|
|
* |
609
|
|
|
* @return AbstractRepository |
610
|
|
|
* |
611
|
|
|
* @throws BadMethodCallException |
612
|
|
|
*/ |
613
|
7 |
|
public function __call($method, $parameters) |
614
|
|
|
{ |
615
|
7 |
|
$pattern = '/^(((where|orWhere).*)|select|limit|groupBy|join|leftJoin|rightJoin|crossJoin|withTrashed|withoutTrashed|onlyTrashed)$/'; |
616
|
7 |
|
if (preg_match($pattern, $method)) { |
617
|
6 |
|
$this->model = call_user_func_array([$this->model, $method], $parameters); |
618
|
6 |
|
return $this; |
619
|
|
|
} |
620
|
|
|
|
621
|
1 |
|
$pattern = '/^(toSql|getBindings)$/'; |
622
|
1 |
|
if (preg_match($pattern, $method)) { |
623
|
|
|
return call_user_func_array([$this->model, $method], $parameters); |
624
|
|
|
} |
625
|
|
|
|
626
|
1 |
|
$className = static::class; |
627
|
1 |
|
throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); |
628
|
|
|
} |
629
|
|
|
} |
630
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..