1 | <?php |
||
8 | abstract class EloquentRepository implements EloquentRepositoryContract |
||
9 | { |
||
10 | /** |
||
11 | * $model. |
||
12 | * |
||
13 | * @var \Illuminate\Database\Eloquent\Model |
||
14 | */ |
||
15 | protected $model; |
||
16 | |||
17 | /** |
||
18 | * __construct. |
||
19 | * |
||
20 | * @param \Illuminate\Database\Eloquent\Model $model |
||
21 | */ |
||
22 | 30 | public function __construct(Model $model) |
|
26 | |||
27 | /** |
||
28 | * Find a model by its primary key. |
||
29 | * |
||
30 | * @param mixed $id |
||
31 | * @param array $columns |
||
32 | * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null |
||
33 | */ |
||
34 | 4 | public function find($id, $columns = ['*']) |
|
38 | |||
39 | /** |
||
40 | * Find multiple models by their primary keys. |
||
41 | * |
||
42 | * @param \Illuminate\Contracts\Support\Arrayable|array $ids |
||
43 | * @param array $columns |
||
44 | * @return \Illuminate\Database\Eloquent\Collection |
||
45 | */ |
||
46 | 1 | public function findMany($ids, $columns = ['*']) |
|
50 | |||
51 | /** |
||
52 | * Find a model by its primary key or throw an exception. |
||
53 | * |
||
54 | * @param mixed $id |
||
55 | * @param array $columns |
||
56 | * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection |
||
57 | * |
||
58 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
59 | */ |
||
60 | 4 | public function findOrFail($id, $columns = ['*']) |
|
64 | |||
65 | /** |
||
66 | * Find a model by its primary key or return fresh model instance. |
||
67 | * |
||
68 | * @param mixed $id |
||
69 | * @param array $columns |
||
70 | * @return \Illuminate\Database\Eloquent\Model |
||
71 | */ |
||
72 | 1 | public function findOrNew($id, $columns = ['*']) |
|
76 | |||
77 | /** |
||
78 | * Get the first record matching the attributes or instantiate it. |
||
79 | * |
||
80 | * @param array $attributes |
||
81 | * @param array $values |
||
82 | * @return \Illuminate\Database\Eloquent\Model |
||
83 | */ |
||
84 | 1 | public function firstOrNew(array $attributes, array $values = []) |
|
88 | |||
89 | /** |
||
90 | * Get the first record matching the attributes or create it. |
||
91 | * |
||
92 | * @param array $attributes |
||
93 | * @param array $values |
||
94 | * @return \Illuminate\Database\Eloquent\Model |
||
95 | */ |
||
96 | 1 | public function firstOrCreate(array $attributes, array $values = []) |
|
100 | |||
101 | /** |
||
102 | * Create or update a record matching the attributes, and fill it with values. |
||
103 | * |
||
104 | * @param array $attributes |
||
105 | * @param array $values |
||
106 | * @return \Illuminate\Database\Eloquent\Model |
||
107 | */ |
||
108 | 1 | public function updateOrCreate(array $attributes, array $values = []) |
|
112 | |||
113 | /** |
||
114 | * Execute the query and get the first result or throw an exception. |
||
115 | * |
||
116 | * @param array $columns |
||
117 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
118 | * @return \Illuminate\Database\Eloquent\Model|static |
||
119 | * |
||
120 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
121 | */ |
||
122 | 1 | public function firstOrFail($criteria = [], $columns = ['*']) |
|
126 | |||
127 | /** |
||
128 | * create. |
||
129 | * |
||
130 | * @param array $attributes |
||
131 | * @return \Illuminate\Database\Eloquent\Model |
||
132 | * |
||
133 | * @throws \Throwable |
||
134 | */ |
||
135 | 1 | public function create($attributes) |
|
139 | |||
140 | /** |
||
141 | * Save a new model and return the instance. |
||
142 | * |
||
143 | * @param array $attributes |
||
144 | * @return \Illuminate\Database\Eloquent\Model |
||
145 | * |
||
146 | * @throws \Throwable |
||
147 | */ |
||
148 | 1 | public function forceCreate($attributes) |
|
152 | |||
153 | /** |
||
154 | * update. |
||
155 | * |
||
156 | * @param array $attributes |
||
157 | * @param mixed $id |
||
158 | * @return \Illuminate\Database\Eloquent\Model |
||
159 | * |
||
160 | * @throws \Throwable |
||
161 | */ |
||
162 | public function update($id, $attributes) |
||
168 | |||
169 | /** |
||
170 | * forceCreate. |
||
171 | * |
||
172 | * @param array $attributes |
||
173 | * @param mixed $id |
||
174 | * @return \Illuminate\Database\Eloquent\Model |
||
175 | * |
||
176 | * @throws \Throwable |
||
177 | */ |
||
178 | public function forceUpdate($id, $attributes) |
||
184 | |||
185 | /** |
||
186 | * delete. |
||
187 | * |
||
188 | * @param mixed $id |
||
189 | */ |
||
190 | 2 | public function delete($id) |
|
194 | |||
195 | /** |
||
196 | * Restore a soft-deleted model instance. |
||
197 | * |
||
198 | * @param mixed $id |
||
199 | * @return bool|null |
||
200 | */ |
||
201 | 1 | public function restore($id) |
|
205 | |||
206 | /** |
||
207 | * Force a hard delete on a soft deleted model. |
||
208 | * |
||
209 | * This method protects developers from running forceDelete when trait is missing. |
||
210 | * |
||
211 | * @param mixed $id |
||
212 | * @return bool|null |
||
213 | */ |
||
214 | 1 | public function forceDelete($id) |
|
218 | |||
219 | /** |
||
220 | * Create a new model instance that is existing. |
||
221 | * |
||
222 | * @param array $attributes |
||
223 | * @return \Illuminate\Database\Eloquent\Model |
||
224 | */ |
||
225 | 1 | public function newInstance($attributes = [], $exists = false) |
|
229 | |||
230 | /** |
||
231 | * Execute the query as a "select" statement. |
||
232 | * |
||
233 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
234 | * @param array $columns |
||
235 | * @return \Illuminate\Support\Collection |
||
236 | */ |
||
237 | 2 | public function get($criteria = [], $columns = ['*']) |
|
241 | |||
242 | /** |
||
243 | * Chunk the results of the query. |
||
244 | * |
||
245 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
246 | * @param int $count |
||
247 | * @param callable $callback |
||
248 | * @return bool |
||
249 | */ |
||
250 | 1 | public function chunk($criteria, $count, callable $callback) |
|
254 | |||
255 | /** |
||
256 | * Execute a callback over each item while chunking. |
||
257 | * |
||
258 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
259 | * @param callable $callback |
||
260 | * @param int $count |
||
261 | * @return bool |
||
262 | */ |
||
263 | 1 | public function each($criteria, callable $callback, $count = 1000) |
|
267 | |||
268 | /** |
||
269 | * Execute the query and get the first result. |
||
270 | * |
||
271 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
272 | * @param array $columns |
||
273 | * @return \Illuminate\Database\Eloquent\Model|static|null |
||
274 | */ |
||
275 | 1 | public function first($criteria = [], $columns = ['*']) |
|
279 | |||
280 | /** |
||
281 | * Paginate the given query. |
||
282 | * |
||
283 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
284 | * @param int $perPage |
||
285 | * @param array $columns |
||
286 | * @param string $pageName |
||
287 | * @param int|null $page |
||
288 | * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
||
289 | * |
||
290 | * @throws \InvalidArgumentException |
||
291 | */ |
||
292 | 1 | public function paginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) |
|
296 | |||
297 | /** |
||
298 | * Paginate the given query into a simple paginator. |
||
299 | * |
||
300 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
301 | * @param int $perPage |
||
302 | * @param array $columns |
||
303 | * @param string $pageName |
||
304 | * @param int|null $page |
||
305 | * @return \Illuminate\Contracts\Pagination\Paginator |
||
306 | */ |
||
307 | 1 | public function simplePaginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) |
|
311 | |||
312 | /** |
||
313 | * Retrieve the "count" result of the query. |
||
314 | * |
||
315 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
316 | * @param string $columns |
||
317 | * @return int |
||
318 | */ |
||
319 | 1 | public function count($criteria = [], $columns = '*') |
|
323 | |||
324 | /** |
||
325 | * Retrieve the minimum value of a given column. |
||
326 | * |
||
327 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
328 | * @param string $column |
||
329 | * @return mixed |
||
330 | */ |
||
331 | 1 | public function min($criteria, $column) |
|
335 | |||
336 | /** |
||
337 | * Retrieve the maximum value of a given column. |
||
338 | * |
||
339 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
340 | * @param string $column |
||
341 | * @return mixed |
||
342 | */ |
||
343 | 1 | public function max($criteria, $column) |
|
347 | |||
348 | /** |
||
349 | * Retrieve the sum of the values of a given column. |
||
350 | * |
||
351 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
352 | * @param string $column |
||
353 | * @return mixed |
||
354 | */ |
||
355 | 1 | public function sum($criteria, $column) |
|
361 | |||
362 | /** |
||
363 | * Retrieve the average of the values of a given column. |
||
364 | * |
||
365 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
366 | * @param string $column |
||
367 | * @return mixed |
||
368 | */ |
||
369 | 2 | public function avg($criteria, $column) |
|
373 | |||
374 | /** |
||
375 | * Alias for the "avg" method. |
||
376 | * |
||
377 | * @param string $column |
||
378 | * @return mixed |
||
379 | */ |
||
380 | 2 | public function average($criteria, $column) |
|
384 | |||
385 | /** |
||
386 | * matching. |
||
387 | * |
||
388 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
389 | * @return \Illuminate\Database\Eloquent\Builder |
||
390 | */ |
||
391 | 16 | public function matching($criteria) |
|
403 | |||
404 | /** |
||
405 | * getQuery. |
||
406 | * |
||
407 | * @param \Recca0120\Repository\Criteria[] $criteria |
||
408 | * @return \Illuminate\Database\Eloquent\Builder |
||
409 | */ |
||
410 | 1 | public function getQuery($criteria = []) |
|
414 | |||
415 | /** |
||
416 | * getModel. |
||
417 | * |
||
418 | * @return \Illuminate\Database\Eloquent\Model |
||
419 | */ |
||
420 | 1 | public function getModel() |
|
426 | |||
427 | /** |
||
428 | * Get a new query builder for the model's table. |
||
429 | * |
||
430 | * @return \Illuminate\Database\Eloquent\Builder |
||
431 | */ |
||
432 | 30 | public function newQuery() |
|
438 | } |
||
439 |