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

Add middleware to web to save session #1710

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Add middleware to web to save session #1710

merged 1 commit into from
Dec 23, 2024

Conversation

barryvdh
Copy link
Owner

The Web middlewaregoup contains the SaveSession middleware, which closes the session. This makes it impossible (as far as I can tell) to save to the session, eg. for redirects.

This will add the middleware to both the regular and the normal group. It will still only boot once and inject once because of the checks, but this should make redirects work again, without any of the workarounds. (#1666 #1662 #1657 #1613 #1591 #1574 #1573) and fixes #1704

@barryvdh barryvdh merged commit af53eda into master Dec 23, 2024
33 checks passed
@shawe
Copy link

shawe commented Dec 26, 2024

It doesn't seem enough for the case where I detected it.

My test case is this:

<?php

namespace App\Http\Requests;

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

class FormRequestValidation extends FormRequest
{
    protected function failedValidation(Validator $validator)
    {
        // Add a message to the Laravel Debugbar
        Debugbar::addMessage($validator->errors()->toArray(), 'Validation failed');
        // Add a message to the Laravel Log
        Log::debug('Validation failed: ' . json_encode($validator->errors()->toArray(), JSON_PRETTY_PRINT));

        // Call the default behavior (throws ValidationException)
        parent::failedValidation($validator);
    }
}

This must show the list of errors when a form is not validated here, but it's not showed.

image

@barryvdh
Copy link
Owner Author

Does the dropdown menu not show up on the right side?

@shawe
Copy link

shawe commented Dec 26, 2024

Does the dropdown menu not show up on the right side?

Yes, and it is in the last request, which should have and display an addMessage capturing the form validation errors.

This may be a very particular problem using Livewire, as it intercepts a thrown exception. I can't remember any other circumstances where I encountered the same problem without using Livewire, so I'll try to see if this fixes it in that case when I remember.

@barryvdh
Copy link
Owner Author

In a redirect, it shows the latest request as last, so you should see the log messages on the first. is that the cases with this PR, or do you not see them at all?

@shawe
Copy link

shawe commented Dec 26, 2024

In a redirect, it shows the latest request as last, so you should see the log messages on the first. is that the cases with this PR, or do you not see them at all?

In this case there is no redirection, the debugbar was showing the last request without problems, the problem it's apparently only with added messages from any type. I have tabs with no data disabled, so there are fewer visible options because they are empty.

@barryvdh
Copy link
Owner Author

Is this livewire? Or why is there no redirect?

@shawe
Copy link

shawe commented Dec 26, 2024

Is this livewire? Or why is there no redirect?

Yes, I say you here:

Does the dropdown menu not show up on the right side?

Yes, and it is in the last request, which should have and display an addMessage capturing the form validation errors.

This may be a very particular problem using Livewire, as it intercepts a thrown exception. I can't remember any other circumstances where I encountered the same problem without using Livewire, so I'll try to see if this fixes it in that case when I remember.

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

Successfully merging this pull request may close these issues.

A lot of issues with not working addMessage in stale state and never solved
2 participants