1 | <?php |
||
10 | abstract class EloquentRepository implements EloquentRepositoryContract |
||
11 | { |
||
12 | /** |
||
13 | * $model. |
||
14 | * |
||
15 | * @var \Illuminate\Database\Eloquent\Model |
||
16 | */ |
||
17 | protected $model; |
||
18 | |||
19 | /** |
||
20 | * |
||
21 | * @var |
||
22 | */ |
||
23 | private $app; |
||
24 | |||
25 | /** |
||
26 | * |
||
27 | * EloquentRepository constructor. |
||
28 | * @param Container $app |
||
29 | */ |
||
30 | public function __construct(Container $app) |
||
36 | |||
37 | |||
38 | /** |
||
39 | * |
||
40 | * @return Model|mixed |
||
41 | */ |
||
42 | protected function makeModel() |
||
52 | |||
53 | /** |
||
54 | * Find a model by its primary key. |
||
55 | * |
||
56 | * @param mixed $id |
||
57 | * @param array $columns |
||
58 | * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null |
||
59 | */ |
||
60 | public function find($id, $columns = ['*']) |
||
64 | |||
65 | /** |
||
66 | * Find multiple models by their primary keys. |
||
67 | * |
||
68 | * @param \Illuminate\Contracts\Support\Arrayable|array $ids |
||
69 | * @param array $columns |
||
70 | * @return \Illuminate\Database\Eloquent\Collection |
||
71 | */ |
||
72 | public function findMany($ids, $columns = ['*']) |
||
76 | |||
77 | /** |
||
78 | * Find a model by its primary key or throw an exception. |
||
79 | * |
||
80 | * @param mixed $id |
||
81 | * @param array $columns |
||
82 | * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection |
||
83 | * |
||
84 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
85 | */ |
||
86 | public function findOrFail($id, $columns = ['*']) |
||
90 | |||
91 | /** |
||
92 | * Find a model by its primary key or return fresh model instance. |
||
93 | * |
||
94 | * @param mixed $id |
||
95 | * @param array $columns |
||
96 | * @return \Illuminate\Database\Eloquent\Model |
||
97 | */ |
||
98 | public function findOrNew($id, $columns = ['*']) |
||
102 | |||
103 | /** |
||
104 | * Get the first record matching the attributes or instantiate it. |
||
105 | * |
||
106 | * @param array $attributes |
||
107 | * @param array $values |
||
108 | * @return \Illuminate\Database\Eloquent\Model |
||
109 | */ |
||
110 | public function firstOrNew(array $attributes, array $values = []) |
||
114 | |||
115 | /** |
||
116 | * Get the first record matching the attributes or create it. |
||
117 | * |
||
118 | * @param array $attributes |
||
119 | * @param array $values |
||
120 | * @return \Illuminate\Database\Eloquent\Model |
||
121 | */ |
||
122 | public function firstOrCreate(array $attributes, array $values = []) |
||
126 | |||
127 | /** |
||
128 | * Create or update a record matching the attributes, and fill it with values. |
||
129 | * |
||
130 | * @param array $attributes |
||
131 | * @param array $values |
||
132 | * @return \Illuminate\Database\Eloquent\Model |
||
133 | */ |
||
134 | public function updateOrCreate(array $attributes, array $values = []) |
||
138 | |||
139 | /** |
||
140 | * Execute the query and get the first result or throw an exception. |
||
141 | * |
||
142 | * @param array $columns |
||
143 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
144 | * @return \Illuminate\Database\Eloquent\Model|static |
||
145 | * |
||
146 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
147 | */ |
||
148 | public function firstOrFail($criteria = [], $columns = ['*']) |
||
152 | |||
153 | /** |
||
154 | * create. |
||
155 | * |
||
156 | * @param array $attributes |
||
157 | * @return \Illuminate\Database\Eloquent\Model |
||
158 | * |
||
159 | * @throws \Throwable |
||
160 | */ |
||
161 | public function create($attributes) |
||
167 | |||
168 | /** |
||
169 | * Save a new model and return the instance. |
||
170 | * |
||
171 | * @param array $attributes |
||
172 | * @return \Illuminate\Database\Eloquent\Model |
||
173 | * |
||
174 | * @throws \Throwable |
||
175 | */ |
||
176 | public function forceCreate($attributes) |
||
182 | |||
183 | /** |
||
184 | * update. |
||
185 | * |
||
186 | * @param array $attributes |
||
187 | * @param mixed $id |
||
188 | * @return \Illuminate\Database\Eloquent\Model |
||
189 | * |
||
190 | * @throws \Throwable |
||
191 | */ |
||
192 | public function update($id, $attributes) |
||
198 | |||
199 | /** |
||
200 | * forceCreate. |
||
201 | * |
||
202 | * @param array $attributes |
||
203 | * @param mixed $id |
||
204 | * @return \Illuminate\Database\Eloquent\Model |
||
205 | * |
||
206 | * @throws \Throwable |
||
207 | */ |
||
208 | public function forceUpdate($id, $attributes) |
||
214 | |||
215 | /** |
||
216 | * delete. |
||
217 | * |
||
218 | * @param mixed $id |
||
219 | */ |
||
220 | public function delete($id) |
||
224 | |||
225 | /** |
||
226 | * Restore a soft-deleted model instance. |
||
227 | * |
||
228 | * @param mixed $id |
||
229 | * @return bool|null |
||
230 | */ |
||
231 | public function restore($id) |
||
235 | |||
236 | /** |
||
237 | * Force a hard delete on a soft deleted model. |
||
238 | * |
||
239 | * This method protects developers from running forceDelete when trait is missing. |
||
240 | * |
||
241 | * @param mixed $id |
||
242 | * @return bool|null |
||
243 | */ |
||
244 | public function forceDelete($id) |
||
248 | |||
249 | /** |
||
250 | * Create a new model instance that is existing. |
||
251 | * |
||
252 | * @param array $attributes |
||
253 | * @return \Illuminate\Database\Eloquent\Model |
||
254 | */ |
||
255 | public function newInstance($attributes = [], $exists = false) |
||
259 | |||
260 | /** |
||
261 | * Execute the query as a "select" statement. |
||
262 | * |
||
263 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
264 | * @param array $columns |
||
265 | * @return \Illuminate\Support\Collection |
||
266 | */ |
||
267 | public function get($criteria = [], $columns = ['*']) |
||
271 | |||
272 | /** |
||
273 | * Chunk the results of the query. |
||
274 | * |
||
275 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
276 | * @param int $count |
||
277 | * @param callable $callback |
||
278 | * @return bool |
||
279 | */ |
||
280 | public function chunk($criteria, $count, callable $callback) |
||
284 | |||
285 | /** |
||
286 | * Execute a callback over each item while chunking. |
||
287 | * |
||
288 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
289 | * @param callable $callback |
||
290 | * @param int $count |
||
291 | * @return bool |
||
292 | */ |
||
293 | public function each($criteria, callable $callback, $count = 1000) |
||
297 | |||
298 | /** |
||
299 | * Execute the query and get the first result. |
||
300 | * |
||
301 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
302 | * @param array $columns |
||
303 | * @return \Illuminate\Database\Eloquent\Model|static|null |
||
304 | */ |
||
305 | public function first($criteria = [], $columns = ['*']) |
||
309 | |||
310 | /** |
||
311 | * Paginate the given query. |
||
312 | * |
||
313 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
314 | * @param int $perPage |
||
315 | * @param array $columns |
||
316 | * @param string $pageName |
||
317 | * @param int|null $page |
||
318 | * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
||
319 | * |
||
320 | * @throws \InvalidArgumentException |
||
321 | */ |
||
322 | public function paginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) |
||
326 | |||
327 | /** |
||
328 | * Paginate the given query into a simple paginator. |
||
329 | * |
||
330 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
331 | * @param int $perPage |
||
332 | * @param array $columns |
||
333 | * @param string $pageName |
||
334 | * @param int|null $page |
||
335 | * @return \Illuminate\Contracts\Pagination\Paginator |
||
336 | */ |
||
337 | public function simplePaginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) |
||
341 | |||
342 | /** |
||
343 | * Retrieve the "count" result of the query. |
||
344 | * |
||
345 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
346 | * @param string $columns |
||
347 | * @return int |
||
348 | */ |
||
349 | public function count($criteria = [], $columns = '*') |
||
353 | |||
354 | /** |
||
355 | * Retrieve the minimum value of a given column. |
||
356 | * |
||
357 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
358 | * @param string $column |
||
359 | * @return mixed |
||
360 | */ |
||
361 | public function min($criteria, $column) |
||
365 | |||
366 | /** |
||
367 | * Retrieve the maximum value of a given column. |
||
368 | * |
||
369 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
370 | * @param string $column |
||
371 | * @return mixed |
||
372 | */ |
||
373 | public function max($criteria, $column) |
||
377 | |||
378 | /** |
||
379 | * Retrieve the sum of the values of a given column. |
||
380 | * |
||
381 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
382 | * @param string $column |
||
383 | * @return mixed |
||
384 | */ |
||
385 | public function sum($criteria, $column) |
||
391 | |||
392 | /** |
||
393 | * Retrieve the average of the values of a given column. |
||
394 | * |
||
395 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
396 | * @param string $column |
||
397 | * @return mixed |
||
398 | */ |
||
399 | 1 | public function avg($criteria, $column) |
|
403 | |||
404 | /** |
||
405 | * Alias for the "avg" method. |
||
406 | * |
||
407 | * @param string $column |
||
408 | * @return mixed |
||
409 | */ |
||
410 | 1 | public function average($criteria, $column) |
|
414 | |||
415 | /** |
||
416 | * matching. |
||
417 | * |
||
418 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
419 | * @return \Illuminate\Database\Eloquent\Builder |
||
420 | */ |
||
421 | 1 | public function matching($criteria) |
|
433 | |||
434 | /** |
||
435 | * getQuery. |
||
436 | * |
||
437 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
438 | * @return \Illuminate\Database\Eloquent\Builder |
||
439 | */ |
||
440 | public function getQuery($criteria = []) |
||
444 | |||
445 | /** |
||
446 | * getModel. |
||
447 | * |
||
448 | * @return \Illuminate\Database\Eloquent\Model |
||
449 | */ |
||
450 | public function getModel() |
||
456 | |||
457 | /** |
||
458 | * Get a new query builder for the model's table. |
||
459 | * |
||
460 | * @return \Illuminate\Database\Eloquent\Builder |
||
461 | */ |
||
462 | 1 | public function newQuery() |
|
468 | } |
||
469 |