@@ -229,21 +229,44 @@ protected function columnsThatShouldBeDeleted(): array
229
229
230
230
public function fillAttribute (RestifyRequest $ request , $ model , ?int $ bulkRow = null )
231
231
{
232
+ // Handle URL input first
233
+ if ($ request ->has ($ this ->attribute ) && is_string ($ request ->input ($ this ->attribute ))) {
234
+ $ url = $ request ->input ($ this ->attribute );
235
+
236
+ if (filter_var ($ url , FILTER_VALIDATE_URL )) {
237
+ if ($ this ->isPrunable ()) {
238
+ call_user_func (
239
+ $ this ->deleteCallback ,
240
+ $ request ,
241
+ $ model ,
242
+ $ this ->getStorageDisk (),
243
+ $ this ->getStoragePath ()
244
+ );
245
+ }
246
+
247
+ $ model ->{$ this ->attribute } = $ url ;
248
+
249
+ if ($ this ->originalNameColumn ) {
250
+ $ model ->{$ this ->originalNameColumn } = basename ($ url );
251
+ }
252
+
253
+ return $ this ;
254
+ }
255
+ }
256
+
257
+ // Existing file upload logic
232
258
if (is_null ($ file = $ request ->file ($ this ->attribute )) || ! $ file ->isValid ()) {
233
259
return $ this ;
234
260
}
235
261
236
262
if ($ this ->isPrunable ()) {
237
- // Delete old file if exists.
238
- // return function () use ($model, $request) {
239
263
call_user_func (
240
264
$ this ->deleteCallback ,
241
265
$ request ,
242
266
$ model ,
243
267
$ this ->getStorageDisk (),
244
268
$ this ->getStoragePath ()
245
269
);
246
- // };
247
270
}
248
271
249
272
$ result = call_user_func (
@@ -276,6 +299,20 @@ public function fillAttribute(RestifyRequest $request, $model, ?int $bulkRow = n
276
299
return $ this ;
277
300
}
278
301
302
+ public function getStoringRules (): array
303
+ {
304
+ $ rules = parent ::getStoringRules ();
305
+
306
+ // Modify validation to accept URLs
307
+ foreach ($ rules as &$ rule ) {
308
+ if (is_string ($ rule ) && Str::startsWith ($ rule , 'file ' )) {
309
+ $ rule = 'sometimes| ' .$ rule ;
310
+ }
311
+ }
312
+
313
+ return $ rules ;
314
+ }
315
+
279
316
/**
280
317
* Get the full path that the field is stored at on disk.
281
318
*
0 commit comments