/**
* @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}'";
}