Spatie\BladeJavaScript\Exceptions\Untransformable::cannotTransformObject PHP Method

cannotTransformObject() public static method

public static cannotTransformObject ( mixed $object ) : static
$object mixed
return static
    public static function cannotTransformObject($object)
    {
        $objectString = print_r($object, true);
        return new static("Cannot transform object {$objectString} to JavaScript.");
    }

Usage Example

 /**
  * @param mixed $value
  *
  * @return string
  *
  * @throws \Spatie\BladeJavaScript\Exceptions\Untransformable
  */
 public function transform($value) : string
 {
     if (method_exists($value, 'toJson')) {
         return $value->toJson();
     }
     if ($value instanceof JsonSerializable || $value instanceof StdClass) {
         return json_encode($value);
     }
     if (!method_exists($value, '__toString')) {
         throw Untransformable::cannotTransformObject($value);
     }
     return "'{$value}'";
 }