@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function deleteCascadedSoftDeletes() : void |
46 | 46 | { |
47 | - if($this->isHardDeleting()) |
|
48 | - return; |
|
47 | + if($this->isHardDeleting()) { |
|
48 | + return; |
|
49 | + } |
|
49 | 50 | |
50 | 51 | if(config('cascaded-soft-deletes.queue_cascades_by_default') === true) { |
51 | 52 | CascadeSoftDeletes::dispatch($this, 'delete', null)->onQueue(config('cascaded-soft-deletes.queue_name')); |
52 | - } |
|
53 | - else { |
|
53 | + } else { |
|
54 | 54 | // @codeCoverageIgnoreStart |
55 | 55 | Str::startsWith(app()->version(), "7") ? |
56 | 56 | CascadeSoftDeletes::dispatchNow($this, 'delete', null) : |
@@ -67,8 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | if(config('cascaded-soft-deletes.queue_cascades_by_default') === true) { |
69 | 69 | CascadeSoftDeletes::dispatch($this, 'restore', static::$instanceDeletedAt)->onQueue(config('cascaded-soft-deletes.queue_name')); |
70 | - } |
|
71 | - else { |
|
70 | + } else { |
|
72 | 71 | // @codeCoverageIgnoreStart |
73 | 72 | Str::startsWith(app()->version(), "7") ? |
74 | 73 | CascadeSoftDeletes::dispatchNow($this, 'restore', static::$instanceDeletedAt) : |
@@ -96,26 +95,30 @@ discard block |
||
96 | 95 | $relations->each(function($item, $key) use ($action, $instanceDeletedAt) { |
97 | 96 | |
98 | 97 | $relation = $key; |
99 | - if(is_numeric($key)) |
|
100 | - $relation = $item; |
|
101 | - |
|
102 | - if(!is_callable($item) && !$this->relationUsesSoftDelete($relation)) |
|
103 | - throw new LogicException('relationship '.$relation.' does not use SoftDeletes trait.'); |
|
104 | - |
|
105 | - if(is_callable($item)) |
|
106 | - $query = $item(); |
|
107 | - else |
|
108 | - $query = $this->{$relation}(); |
|
109 | - |
|
110 | - if($action == 'delete') |
|
111 | - $query->get()->each->delete(); |
|
112 | - else |
|
113 | - $query |
|
98 | + if(is_numeric($key)) { |
|
99 | + $relation = $item; |
|
100 | + } |
|
101 | + |
|
102 | + if(!is_callable($item) && !$this->relationUsesSoftDelete($relation)) { |
|
103 | + throw new LogicException('relationship '.$relation.' does not use SoftDeletes trait.'); |
|
104 | + } |
|
105 | + |
|
106 | + if(is_callable($item)) { |
|
107 | + $query = $item(); |
|
108 | + } else { |
|
109 | + $query = $this->{$relation}(); |
|
110 | + } |
|
111 | + |
|
112 | + if($action == 'delete') { |
|
113 | + $query->get()->each->delete(); |
|
114 | + } else { |
|
115 | + $query |
|
114 | 116 | ->onlyTrashed() |
115 | 117 | ->where($this->getDeletedAtColumn(), '>=', $instanceDeletedAt->format('Y-m-d H:i:s.u')) |
116 | 118 | ->get() |
117 | 119 | ->each |
118 | 120 | ->restore(); |
121 | + } |
|
119 | 122 | |
120 | 123 | // else { |
121 | 124 | // $query = $query |
@@ -167,8 +170,9 @@ discard block |
||
167 | 170 | { |
168 | 171 | static $softDeletes; |
169 | 172 | |
170 | - if(is_null($softDeletes)) |
|
171 | - $softDeletes = collect([]); |
|
173 | + if(is_null($softDeletes)) { |
|
174 | + $softDeletes = collect([]); |
|
175 | + } |
|
172 | 176 | |
173 | 177 | return $softDeletes->get($relation, function() use($relation, $softDeletes) { |
174 | 178 | $instance = new static; |