JsonEncodingException.php 900B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Illuminate\Database\Eloquent;
  3. use RuntimeException;
  4. class JsonEncodingException extends RuntimeException
  5. {
  6. /**
  7. * Create a new JSON encoding exception for the model.
  8. *
  9. * @param mixed $model
  10. * @param string $message
  11. * @return static
  12. */
  13. public static function forModel($model, $message)
  14. {
  15. return new static('Error encoding model ['.get_class($model).'] with ID ['.$model->getKey().'] to JSON: '.$message);
  16. }
  17. /**
  18. * Create a new JSON encoding exception for an attribute.
  19. *
  20. * @param mixed $model
  21. * @param mixed $key
  22. * @param string $message
  23. * @return static
  24. */
  25. public static function forAttribute($model, $key, $message)
  26. {
  27. $class = get_class($model);
  28. return new static("Unable to encode attribute [{$key}] for model [{$class}] to JSON: {$message}.");
  29. }
  30. }