@@ -60,6 +60,7 @@ private function registerSubfieldEvent(array $subfield, bool $registerModelEvent
60
60
$ uploader = $ this ->getUploader ($ subfield , $ this ->uploaderConfiguration );
61
61
$ crudObject = $ this ->crudObject ->getAttributes ();
62
62
$ uploader = $ uploader ->repeats ($ crudObject ['name ' ]);
63
+ $ uploader = $ uploader ->fake ((isset ($ crudObject ['fake ' ]) && $ crudObject ['fake ' ]) ? ($ crudObject ['store_in ' ] ?? 'extras ' ) : false );
63
64
64
65
// If this uploader is already registered bail out. We may endup here multiple times when doing modifications to the crud object.
65
66
// Changing `subfields` properties will call the macros again. We prevent duplicate entries by checking
@@ -139,6 +140,14 @@ private function setupModelEvents(string $model, UploaderInterface $uploader): v
139
140
$ uploader ->deleteUploadedFiles ($ entry );
140
141
});
141
142
143
+ // if the uploader is a relationship and handles repeatable files, we will also register the deleting event on the
144
+ // parent model. that way we can control the deletion of the files when the parent model is deleted.
145
+ if ($ uploader ->isRelationship () && $ uploader ->handleRepeatableFiles ) {
146
+ app ('crud ' )->model ::deleting (function ($ entry ) use ($ uploader ) {
147
+ $ uploader ->deleteUploadedFiles ($ entry );
148
+ });
149
+ }
150
+
142
151
app ('UploadersRepository ' )->markAsHandled ($ uploader ->getIdentifier ());
143
152
}
144
153
@@ -154,9 +163,13 @@ private function setupModelEvents(string $model, UploaderInterface $uploader): v
154
163
*/
155
164
private function getUploader (array $ crudObject , array $ uploaderConfiguration ): UploaderInterface
156
165
{
157
- $ customUploader = isset ($ uploaderConfiguration ['uploader ' ]) && class_exists ($ uploaderConfiguration ['uploader ' ]);
166
+ $ hasCustomUploader = isset ($ uploaderConfiguration ['uploader ' ]);
167
+
168
+ if ($ hasCustomUploader && ! is_a ($ uploaderConfiguration ['uploader ' ], UploaderInterface::class, true )) {
169
+ throw new Exception ('Invalid uploader class provided for ' .$ this ->crudObjectType .' type: ' .$ crudObject ['type ' ]);
170
+ }
158
171
159
- if ($ customUploader ) {
172
+ if ($ hasCustomUploader ) {
160
173
return $ uploaderConfiguration ['uploader ' ]::for ($ crudObject , $ uploaderConfiguration );
161
174
}
162
175
0 commit comments