outl1ne / nova-simple-repeatable

A Laravel Nova simple repeatable rows field.
MIT License
73 stars 42 forks source link

Image upload feature #17

Closed ahmetbedir closed 1 year ago

ahmetbedir commented 3 years ago

There was a problem with the image fields, I made some updates to use the image fields.

Tarpsvo commented 3 years ago

Hey! Did you test this?

ahmetbedir commented 3 years ago

Hey! Did you test this?

I tested it again. Uploading and previewing images does not appear to be a problem either. But the image deletion is not working correctly now. The DELETE request results in a 404 because Nova cannot find the relevant field. Consider creating a unique attribute name Example: "user_details---avatar---0" when there is no field with that name, the result will be 404. We probably won't be solving this with the existing Image component. Because we will need to override the following findFieldByAttribute method in the FieldDestroyController@handle method. You can see the part where it gives the 404 error in the code block below. I will deal with this issue at a later date.

public function handle(NovaRequest $request)
{
    $resource = $request->findResourceOrFail();

    $resource->authorizeToUpdate($request);

    $field = $resource->updateFields($request)
                ->whereInstanceOf(Downloadable::class)
                ->findFieldByAttribute($request->field, function () {
                    abort(404);
                });

    DeleteField::forRequest(
        $request, $field, $resource->resource
    )->save();

    Nova::actionEvent()->forResourceUpdate(
        $request->user(), $resource->resource
    )->save();
}