laravel-debugbar icon indicating copy to clipboard operation
laravel-debugbar copied to clipboard

Laravel flash messages not working after update to 3.13

Open cedricpri opened this issue 1 year ago • 8 comments

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!

cedricpri avatar Apr 09 '24 14:04 cedricpri

Any idea where this behaviour might come from?

maybe #1591

parallels999 avatar Apr 09 '24 14:04 parallels999

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.

cedricpri avatar Apr 09 '24 14:04 cedricpri

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

parallels999 avatar Apr 09 '24 14:04 parallels999

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 avatar Apr 10 '24 08:04 barryvdh

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

barryvdh avatar Apr 10 '24 08:04 barryvdh

@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

jakublacko avatar Apr 10 '24 09:04 jakublacko

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

barryvdh avatar Apr 10 '24 09:04 barryvdh

New attempt in https://github.com/barryvdh/laravel-debugbar/pull/1657

barryvdh avatar Sep 10 '24 09:09 barryvdh