Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A lot of issues with not working addMessage in stale state and never solved #1704

Open
shawe opened this issue Nov 22, 2024 · 0 comments
Open

Comments

@shawe
Copy link

shawe commented Nov 22, 2024

I'm having this issue that are also related to this:

I'm having the same issue trying to force to appear a message to give visibility to an improperly controlled error.

In my case, I found that a FormRequest with an improperly validation, can cause not pass a validation and not see the error. I think to show it on debugbar for get the needed feedback that what is happening.

I try to do a Middleware to catch the error, dd show the message that debugbar:addMessage doesn't show.
I try to do another class to extends, that have failedValidation, and the same problem. And in this point I try some other things.

This is my final test, that seems to show a non expected behaviour:

<?php

namespace App\Http\Requests;

use Barryvdh\Debugbar\Facades\Debugbar;
use Exception;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;


class FormRequestValidation extends FormRequest
{
    /**
     * Manejar la validación fallida.
     */
    protected function failedValidation(Validator $validator)
    {
        // Registrar errores en Debugbar
        Debugbar::addMessage($validator->errors()->toArray(), 'Validation failed');

        // throw new Exception('Validation failed: ' . json_encode($validator->errors()->toArray(), JSON_PRETTY_PRINT));

        // Llamar al comportamiento predeterminado (lanza ValidationException)
        parent::failedValidation($validator);
    }
}

With the throw commented, I can't see messages on debugbar.
With the throw uncommented, I can see TWO messages on debugbar.

To try to reproduce this problem, is only needed a form validation with a required field that is not submited.

What is the solution? I don't know, but a lot of people seems to have this kind of problem, but no solution with a problem that seems to happen from nearly 2014.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant