json, $key, $value); } /** * Retrieves a value from the underlying JSON array. * * @param string $key * @param string|int|null $default * @return string|int|null */ public function get(string $key, string|int $default = null): string|int|null { return Arr::get($this->json, $key, $default); } /** * Convert the object to its JSON representation. * * @param int $options * @return string */ public function toJson($options = 0): string { return json_encode($this->jsonSerialize(), JSON_THROW_ON_ERROR | $options); } /** * Get the instance as an array. * * @return array */ public function toArray() { return $this->json; } /** * Specify data which should be serialized to JSON. * * @return array */ public function jsonSerialize(): array { return $this->toArray(); } /** * Returns a string representation of the object. * * @return string */ public function __toString(): string { return $this->toJson(); } /** * Create an HTTP response that represents the object. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ public function toResponse($request): JsonResponse { return new JsonResponse($this); } }