From 31f263035a0d4475df341dde3c46914f08ee446d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20R=C3=BCtter?= Date: Wed, 15 Jul 2026 16:43:49 +0200 Subject: [PATCH] Make toasts survive JSON session serialization Co-Authored-By: Claude Fable 5 --- src/CP/Toasts/Toast.php | 8 +++++++- tests/CP/Toasts/ManagerTest.php | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/CP/Toasts/ManagerTest.php diff --git a/src/CP/Toasts/Toast.php b/src/CP/Toasts/Toast.php index 57ad55a6a16..b53ad1f34f1 100644 --- a/src/CP/Toasts/Toast.php +++ b/src/CP/Toasts/Toast.php @@ -4,11 +4,12 @@ use Exception; use Illuminate\Contracts\Support\Arrayable; +use JsonSerializable; /** * Holds information about a toast message to show to the user. */ -class Toast implements Arrayable +class Toast implements Arrayable, JsonSerializable { private const TYPES = ['error', 'success', 'info']; private $message; @@ -43,6 +44,11 @@ public function toArray(): array ]; } + public function jsonSerialize(): array + { + return $this->toArray(); + } + /** * @throws Exception */ diff --git a/tests/CP/Toasts/ManagerTest.php b/tests/CP/Toasts/ManagerTest.php new file mode 100644 index 00000000000..4adb36713a4 --- /dev/null +++ b/tests/CP/Toasts/ManagerTest.php @@ -0,0 +1,35 @@ +start(); + (new Manager($session))->success('Saved!'); + $session->save(); + + // Read it back on the "next request". + $session = new Store('test', $handler, $sessionId, 'json'); + $session->start(); + + $this->assertSame( + [['message' => 'Saved!', 'type' => 'success', 'duration' => null]], + (new Manager($session))->toArray() + ); + } +}