| Total Complexity | 6 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | trait SoftDeleteTrait |
||
| 9 | { |
||
| 10 | protected string $softDeleteField = 'deleted_at'; |
||
| 11 | |||
| 12 | public function applySoftDeletedConditions(Builder $query): Builder |
||
| 13 | { |
||
| 14 | return $query->whereNotNull($this->softDeleteField); |
||
| 15 | } |
||
| 16 | |||
| 17 | public function applyNotSoftDeletedConditions(Builder $query): Builder |
||
| 18 | { |
||
| 19 | return $query->whereNull($this->softDeleteField); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function trash($id): bool |
||
| 23 | { |
||
| 24 | $currentTime = Carbon::now('UTC')->format('Y-m-d H:i:s'); |
||
| 25 | $data = $this->getById($id); |
||
|
|
|||
| 26 | if (!$data) { |
||
| 27 | return false; |
||
| 28 | } |
||
| 29 | return $this->update($id, [$this->softDeleteField => $currentTime], true); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function restore($id): bool |
||
| 39 | } |
||
| 40 | } |
||
| 41 |