3 namespace Illuminate\Support
;
6 use Carbon\Carbon
as BaseCarbon
;
7 use Illuminate\Support\Traits\Macroable
;
9 class Carbon
extends BaseCarbon
implements JsonSerializable
14 * The custom Carbon JSON serializer.
18 protected static $serializer;
21 * Prepare the object for JSON serialization.
23 * @return array|string
25 public function jsonSerialize()
27 if (static::$serializer) {
28 return call_user_func(static::$serializer, $this);
33 return call_user_func(function () use ($carbon) {
34 return get_object_vars($carbon);
39 * JSON serialize all Carbon instances using the given callback.
41 * @param callable $callback
44 public static function serializeUsing($callback)
46 static::$serializer = $callback;