barryvdh / laravel-debugbar

Debugbar for Laravel (Integrates PHP Debug Bar)
MIT License
16.57k stars 1.53k forks source link

Laravel flash messages not working after update to 3.13 #1612

Open cedricpri opened 3 months ago

cedricpri commented 3 months ago

Hello!

I've been using the debugbar for a while now and I have been quite happy so far, thanks for the hard work!

Anyway, I started having issues with my app last week. After rebuilding the containers (and updating the debugbar to the last version, 3.13.3) my app Laravel/Inertia/App suddenly stopped working. Basically, all the flashed messages from Laravel weren't picked up by Inertia, therefore breaking some features in my app.

In particular, I defined a vue component which simply calls a "/test" endpoint when mounted. This endpoint contains the following code:

public function testMethod()
  {
      session()->put("success", "message1");
      return back()->with("testMessage", "message2");
  }

I then defined an Inertia Middleware to intercept this flashed message and show in the frontend as per their documentation:

public function share(Request $request): array
  {
      return array_merge(parent::share($request), [
          "flash" => function () {
              return [
                  "testMessage" => session()->get("testMessage"),
                  "success" => session()->get("success"),
                  "error" => session()->get("error"),
                  "status" => session()->get("status"),
                  "data" => session()->get("data")
              ];
          },
      ]);
  }

However, the flashed message was never found under any circumstance while this used to work perfectly fine. After a few days of investigations, I realized that reverting the debugbar back to 3.12.4 apparently solves the issue.

Any idea where this behaviour might come from? Thank you!

parallels999 commented 3 months ago

Any idea where this behaviour might come from?

maybe #1591

cedricpri commented 3 months ago

The session appears to be saved in my case(the success message does show up in my Middleware) but the flashed data doesn't seem to be.

parallels999 commented 3 months ago

If you find the problem feel free to open a PR with the fix

barryvdh commented 3 months ago

I'm not 100% but I think the moment we add our stacked data to the session, the session is already saved so we re-flash the messages. But it seems that you also try to change it in the middleware, so might be a timing issue. Not really sure what the safest way is.

barryvdh commented 3 months ago

I tried the flashing with default Laravel installations and existing project, and there the flash messages keep working + redirect show in the tabs. But not sure about Intertia

jakublacko commented 3 months ago

@barryvdh We do not have inertia in the project and still after updating to 3.13 all the flash messages stopped working. Downgrade to 3.12 helped for now

barryvdh commented 3 months ago

Hmm I've reverted it again. Will try to find something without re-flashing. https://github.com/barryvdh/laravel-debugbar/pull/1613