如何制作 Laravel 对象集合而不是数组

How to make Laravel Collection of Object instead of Array

如何制作 Laravel 对象集合而不是数组?

如果我这样做:

$result = collect([
    'foo' => [
        'success' => 0,
        'failed' => 0
    ],
    'bar' => [
        'success' => 0,
        'failed' => 0
    ]
]);

我将获得 laravel 数组集合的新实例。但是,如何创建对象集合而不是数组?

使用这个:

$result = json_decode(
    collect([
        'foo' => [
            'success' => 0,
            'failed' => 0
        ],
        'bar' => [
            'success' => 0,
            'failed' => 0
        ]
    ])->toJson()
);