diff --git a/src/Illuminate/Database/Eloquent/JsonEncodingException.php b/src/Illuminate/Database/Eloquent/JsonEncodingException.php new file mode 100644 index 000000000000..84f577a62ca6 --- /dev/null +++ b/src/Illuminate/Database/Eloquent/JsonEncodingException.php @@ -0,0 +1,20 @@ +getKey().'] to JSON: '.$message); + } +} diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 8a6accc59a4b..8bca4095d8f0 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2415,14 +2415,14 @@ public function setIncrementing($value) * @param int $options * @return string * - * @throws \InvalidArgumentException + * @throws JsonEncodingException */ public function toJson($options = 0) { $json = json_encode($this->jsonSerialize(), $options); if (JSON_ERROR_NONE !== json_last_error()) { - throw new InvalidArgumentException(json_last_error_msg()); + throw JsonEncodingException::forModel($this, json_last_error_msg()); } return $json;