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() + ); + } +}