@@ -150,43 +150,7 @@ private function getUploaderFieldSubfields()
150150 private function deleteRepeatableFiles (Model $ entry ): void
151151 {
152152 if ($ this ->isRelationship ) {
153- switch ($ this ->getRepeatableRelationType ()) {
154- case 'BelongsToMany ' :
155- case 'MorphToMany ' :
156- $ pivotAttributes = $ entry ->getAttributes ();
157- $ connectedPivot = $ entry ->pivotParent ->{$ this ->getRepeatableContainerName ()}->where (function ($ item ) use ($ pivotAttributes ) {
158- $ itemPivotAttributes = $ item ->pivot ->only (array_keys ($ pivotAttributes ));
159-
160- return $ itemPivotAttributes === $ pivotAttributes ;
161- })->first ();
162-
163- if (! $ connectedPivot ) {
164- return ;
165- }
166-
167- $ files = $ connectedPivot ->getOriginal ()['pivot_ ' .$ this ->getAttributeName ()];
168-
169- if (! $ files ) {
170- return ;
171- }
172-
173- if (is_array ($ files )) {
174- foreach ($ files as $ value ) {
175- $ value = Str::start ($ value , $ this ->getPath ());
176- Storage::disk ($ this ->getDisk ())->delete ($ value );
177- }
178-
179- return ;
180- }
181-
182- $ value = Str::start ($ files , $ this ->getPath ());
183- Storage::disk ($ this ->getDisk ())->delete ($ value );
184-
185- return ;
186- }
187-
188- $ this ->deleteFiles ($ entry );
189-
153+ $ this ->deleteRelationshipFiles ($ entry );
190154 return ;
191155 }
192156
@@ -272,4 +236,42 @@ private function getValuesWithPathStripped(array|string|null $item, UploaderInte
272236
273237 return isset ($ uploadedValues ) ? Str::after ($ uploadedValues , $ upload ->getPath ()) : null ;
274238 }
239+
240+ private function deleteRelationshipFiles (Model $ entry ) : void
241+ {
242+ if (in_array ($ this ->getRepeatableRelationType (), ['BelongsToMany ' , 'MorphToMany ' ])) {
243+ $ pivotAttributes = $ entry ->getAttributes ();
244+ $ connectedPivot = $ entry ->pivotParent ->{$ this ->getRepeatableContainerName ()}->where (function ($ item ) use ($ pivotAttributes ) {
245+ $ itemPivotAttributes = $ item ->pivot ->only (array_keys ($ pivotAttributes ));
246+
247+ return $ itemPivotAttributes === $ pivotAttributes ;
248+ })->first ();
249+
250+ if (! $ connectedPivot ) {
251+ return ;
252+ }
253+
254+ $ files = $ connectedPivot ->getOriginal ()['pivot_ ' .$ this ->getAttributeName ()];
255+
256+ if (! $ files ) {
257+ return ;
258+ }
259+
260+ if (is_array ($ files )) {
261+ foreach ($ files as $ value ) {
262+ $ value = Str::start ($ value , $ this ->getPath ());
263+ Storage::disk ($ this ->getDisk ())->delete ($ value );
264+ }
265+
266+ return ;
267+ }
268+
269+ $ value = Str::start ($ files , $ this ->getPath ());
270+ Storage::disk ($ this ->getDisk ())->delete ($ value );
271+
272+ return ;
273+ }
274+
275+ $ this ->deleteFiles ($ entry );
276+ }
275277}
0 commit comments