1 | <?php |
||
18 | abstract class AbstractRepository implements ContractInterface |
||
19 | { |
||
20 | protected $with = []; |
||
21 | /** |
||
22 | * @var App |
||
23 | */ |
||
24 | protected $app; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $order = null; |
||
28 | |||
29 | protected $direction = 'desc'; |
||
30 | /** |
||
31 | * @var Entity |
||
32 | */ |
||
33 | protected $model; |
||
34 | /** |
||
35 | * @var boolean |
||
36 | */ |
||
37 | private $trash = false; |
||
38 | /** |
||
39 | * @var boolean |
||
40 | */ |
||
41 | private $withTrash = false; |
||
42 | |||
43 | /** |
||
44 | * @param App $app |
||
45 | */ |
||
46 | public function __construct(App $app) |
||
51 | |||
52 | protected function makeModel() |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | abstract protected function getModelClass(): string; |
||
61 | |||
62 | /** |
||
63 | * @param int $limit |
||
64 | * @param array $filters |
||
65 | * |
||
66 | * @return \Illuminate\Contracts\Pagination\Paginator |
||
67 | */ |
||
68 | public function simplePaginate($limit = 10, $filters = []) |
||
72 | |||
73 | /** |
||
74 | * @param array $filters |
||
75 | * @return Entity |
||
76 | */ |
||
77 | public function filter($filters = []) |
||
104 | |||
105 | /** |
||
106 | * prepare order for query |
||
107 | * |
||
108 | * @param array $filters |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | private function order($filters=[]){ |
||
127 | |||
128 | /** |
||
129 | * @param int $limit |
||
130 | * @param array $filters |
||
131 | * |
||
132 | * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
||
133 | */ |
||
134 | public function paginate($limit = 10, $filters = []) |
||
138 | |||
139 | /** |
||
140 | * @param array $filters |
||
141 | * |
||
142 | * @return Builder[]|\Illuminate\Database\Eloquent\Collection |
||
143 | */ |
||
144 | public function get($filters = []) |
||
148 | |||
149 | /** |
||
150 | * @param $entityId |
||
151 | * @param array $attributes |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function update($entityId = 0, $attributes = []) |
||
165 | |||
166 | /** |
||
167 | * @param $entityId |
||
168 | * |
||
169 | * @throws \Exception |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function delete($entityId = 0) |
||
179 | |||
180 | /** |
||
181 | * @param array $attributes |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | public function insert($attributes = []) |
||
189 | |||
190 | |||
191 | /** |
||
192 | * @param array $columns |
||
193 | * |
||
194 | * @return mixed |
||
195 | */ |
||
196 | public function all($columns = ['*']) |
||
200 | |||
201 | /** |
||
202 | * @param string $name |
||
203 | * @param string $entityId |
||
204 | * @param array $filters |
||
205 | * |
||
206 | * @return array |
||
207 | */ |
||
208 | public function pluck($name = 'name', $entityId = 'id', $filters = []) |
||
212 | |||
213 | /** |
||
214 | * @param $entityId |
||
215 | * @param array $columns |
||
216 | * |
||
217 | * @return Entity |
||
218 | */ |
||
219 | public function find($entityId = 0, $columns = ['*']) |
||
223 | |||
224 | /** |
||
225 | * @param array $filter |
||
226 | * @param array $columns |
||
227 | * |
||
228 | * @return Entity |
||
229 | */ |
||
230 | public function first($filter = [], $columns = ['*']) |
||
234 | |||
235 | /** |
||
236 | * @param $haystack |
||
237 | * @param $needle |
||
238 | * |
||
239 | * @return Entity[]|\Illuminate\Database\Eloquent\Collection |
||
240 | */ |
||
241 | public function search($haystack, $needle) |
||
245 | |||
246 | |||
247 | /** |
||
248 | * @param $filters |
||
249 | * @param array $columns |
||
250 | * |
||
251 | * @return Entity |
||
252 | */ |
||
253 | public function findBy($filters = [], $columns = ['*']) |
||
257 | |||
258 | /** |
||
259 | * @param array $attributes |
||
260 | * |
||
261 | * @return Entity|\Illuminate\Database\Eloquent\Model |
||
262 | */ |
||
263 | public function create($attributes = []) |
||
267 | |||
268 | /** |
||
269 | * @param array $attributes |
||
270 | * |
||
271 | * @return Entity|\Illuminate\Database\Eloquent\Model |
||
272 | */ |
||
273 | public function createOrUpdate($attributes = []) |
||
277 | |||
278 | /** |
||
279 | * @param array $data |
||
280 | * |
||
281 | * @return \Illuminate\Database\Eloquent\Model |
||
282 | */ |
||
283 | public function createOrFirst($data = []) |
||
287 | |||
288 | /** |
||
289 | * Get entity name |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function entityName() |
||
297 | |||
298 | /** |
||
299 | * @param int $entityId |
||
300 | * |
||
301 | * @return bool|null |
||
302 | */ |
||
303 | public function restore($entityId = 0) |
||
315 | |||
316 | /** |
||
317 | * @param int $entityId |
||
318 | * |
||
319 | * @return bool|null |
||
320 | */ |
||
321 | public function forceDelete($entityId = 0) |
||
333 | |||
334 | /** |
||
335 | * @return void |
||
336 | */ |
||
337 | public function trash() |
||
342 | |||
343 | /** |
||
344 | * @return void |
||
345 | */ |
||
346 | public function withTrash() |
||
351 | } |
||
352 |