1 | <?php |
||
18 | abstract class AbstractRepository implements Contract |
||
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 = []) |
||
113 | |||
114 | /** |
||
115 | * @param int $limit |
||
116 | * @param array $filters |
||
117 | * |
||
118 | * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
||
119 | */ |
||
120 | public function paginate($limit = 10, $filters = []) |
||
124 | |||
125 | /** |
||
126 | * @param array $filters |
||
127 | * |
||
128 | * @return Builder[]|\Illuminate\Database\Eloquent\Collection |
||
129 | */ |
||
130 | public function get($filters = []) |
||
134 | |||
135 | /** |
||
136 | * @param $entityId |
||
137 | * @param array $attributes |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function update($entityId = 0, $attributes = []) |
||
151 | |||
152 | /** |
||
153 | * @param $entityId |
||
154 | * |
||
155 | * @throws \Exception |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function delete($entityId = 0) |
||
165 | |||
166 | /** |
||
167 | * @param array $attributes |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function insert($attributes = []) |
||
175 | |||
176 | |||
177 | /** |
||
178 | * @param array $columns |
||
179 | * |
||
180 | * @return mixed |
||
181 | */ |
||
182 | public function all($columns = ['*']) |
||
186 | |||
187 | /** |
||
188 | * @param string $name |
||
189 | * @param string $entityId |
||
190 | * @param array $filters |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | public function pluck($name = 'name', $entityId = 'id', $filters = []) |
||
198 | |||
199 | /** |
||
200 | * @param $entityId |
||
201 | * @param array $columns |
||
202 | * |
||
203 | * @return Entity |
||
204 | */ |
||
205 | public function find($entityId = 0, $columns = ['*']) |
||
209 | |||
210 | /** |
||
211 | * @param array $filter |
||
212 | * @param array $columns |
||
213 | * |
||
214 | * @return Entity |
||
215 | */ |
||
216 | public function first($filter = [], $columns = ['*']) |
||
220 | |||
221 | /** |
||
222 | * @param $haystack |
||
223 | * @param $needle |
||
224 | * |
||
225 | * @return Entity[]|\Illuminate\Database\Eloquent\Collection |
||
226 | */ |
||
227 | public function search($haystack, $needle) |
||
231 | |||
232 | |||
233 | /** |
||
234 | * @param $filters |
||
235 | * @param array $columns |
||
236 | * |
||
237 | * @return Entity |
||
238 | */ |
||
239 | public function findBy($filters = [], $columns = ['*']) |
||
243 | |||
244 | /** |
||
245 | * @param array $attributes |
||
246 | * |
||
247 | * @return Entity|\Illuminate\Database\Eloquent\Model |
||
248 | */ |
||
249 | public function create($attributes = []) |
||
253 | |||
254 | /** |
||
255 | * @param array $attributes |
||
256 | * |
||
257 | * @return Entity|\Illuminate\Database\Eloquent\Model |
||
258 | */ |
||
259 | public function createOrUpdate($attributes = []) |
||
263 | |||
264 | /** |
||
265 | * @param array $data |
||
266 | * |
||
267 | * @return \Illuminate\Database\Eloquent\Model |
||
268 | */ |
||
269 | public function createOrFirst($data = []) |
||
273 | |||
274 | /** |
||
275 | * Get entity name |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | public function entityName() |
||
283 | |||
284 | /** |
||
285 | * @param int $entityId |
||
286 | * |
||
287 | * @return bool|null |
||
288 | */ |
||
289 | public function restore($entityId = 0) |
||
301 | |||
302 | /** |
||
303 | * @param int $entityId |
||
304 | * |
||
305 | * @return bool|null |
||
306 | */ |
||
307 | public function forceDelete($entityId = 0) |
||
319 | |||
320 | /** |
||
321 | * @return void |
||
322 | */ |
||
323 | public function trash() |
||
328 | |||
329 | /** |
||
330 | * @return void |
||
331 | */ |
||
332 | public function withTrash() |
||
337 | } |
||
338 |