Laravel-Backpack / community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
28 stars 0 forks source link

[Editable Columns] [Bug] [Minor improvement] Empty custom messages #838

Closed rahman-nero closed 4 months ago

rahman-nero commented 4 months ago

Hello. Using editable-columns package but it's got some problems with custom messages while returning errors from validation.

It doesn't take custom messages and attributes from set FormRequest. So I fixed it:

    public function saveMinorUpdateFormValidation()
    {
        $input = request()->only(['id', 'attribute', 'value', 'row']);

        // Validate attribute is fillable
        if (!$this->crud->model->isFillable($input['attribute'])) {
            throw ValidationException::withMessages([
                $input['attribute'] => [__('backpack.editable-columns::minor_update.error_fillable', $input)],
            ]);
        }

        // Setting the value to its own key (for correct validation error messages)
        $input[$input['attribute']] = $input['value'];

        // Form Validation
        $formRequest = $this->crud->getFormRequest();
        if ($formRequest) {
            $formRequestObject = new $formRequest();
            $attributes = $formRequestObject->attributes();
            $messages = $formRequestObject->messages();
            $rules = $formRequestObject->rules();

            $validator = Validator::make($input, [
                $input['attribute'] => $rules[$input['attribute']] ?? '',
            ], $messages, $attributes);

            if ($validator->fails()) {
                throw new ValidationException($validator);
            }
        }
    }

I hope you add it in future release (because I don't like to custom it in my project)

karandatwani92 commented 4 months ago

Hey @rahman-nero

Thanks for reporting it. I appreciate your effort for the fix.❤️ While my testing, your fix worked! I've submitted your fix and assigned my colleague to review & merge.

I will update here once it gets merged.

Cheers!

pxpm commented 4 months ago

Hey @rahman-nero thanks for the report .

We have just tagged editable-columns 3.0.6 with a fix for this.

Our private repository should pick the change in a while and you will be able to get it with a composer update

Cheers