outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
271 stars 98 forks source link

Files uploaded with Trix are not uploaded #119

Open fkeloks opened 2 years ago

fkeloks commented 2 years ago

Hello,

The upload of attachments (images or videos for example) does not work with the Trix editor (the default editor of Nova).

Example:

NovaSettings::addSettingsFields([
    Panel::make('Homepage - event 1', [
        Text::make('Name', 'event_1_name')->rules('required', 'max:100'),
        Trix::make('Description', 'event_1_description')->withFiles('public')->rules('required', 'max:64000'),
    ]),
]);

On upload, the request is:

Request URL: http://localhost:8000/nova-api/nova-settings/trix-attachment/event_1_description
Request Method: POST
Status Code: 404 Not Found

on vendor/laravel/nova/src/Http/Controllers/TrixAttachmentController.php:

    public function store(NovaRequest $request)
    {
        $field = $request->newResource()
                        ->availableFields($request)
                        ->findFieldByAttribute($request->field, function () {
                            abort(404);
                        });

        return response()->json(['url' => call_user_func(
            $field->attachCallback, $request
        )]);
    }

Indeed, instead of "value" (from the Settings model) the field is "event_1_description", which causes the 404 error and prevents the upload