如何从laravel中的集合中读取数据

如何从laravel中的集合中读取数据,laravel,Laravel,嗨,我是拉雷维尔的新手,我有这个系列 $details = collect([ ['total' => Valeur::all()->count()], ['instance' => Valeur::where('etat', 1)->count()], ['deposer' => Valeur::where('etat', 2)->count()], ['enca

嗨,我是拉雷维尔的新手,我有这个系列

$details = collect([
            ['total' => Valeur::all()->count()],
            ['instance' => Valeur::where('etat', 1)->count()],
            ['deposer' => Valeur::where('etat', 2)->count()],
            ['encaisse' => Valeur::where('etat', 3)->count()],
            ['retourne' => Valeur::where('etat', 4)->count()],
            ]);
我想知道如何读取这样的数据

$details->total;

如果您有一个数组,那么您需要对它进行迭代,以便根据需要访问它。但在我看来,这应该是数组的一项,所以如果您这样更改它:

$details = collect([
    'total' => Valeur::all()->count(),
    'instance' => Valeur::where('etat', 1)->count(),
    'deposer' => Valeur::where('etat', 2)->count(),
    'encaisse' => Valeur::where('etat', 3)->count(),
    'retourne' => Valeur::where('etat', 4)->count(),
]);

然后您将能够像
$details->get('total')一样访问它
$details['total']

如果您有一个数组数组,则需要对其进行迭代,以便根据需要访问它。但在我看来,这应该是数组的一项,所以如果您这样更改它:

$details = collect([
    'total' => Valeur::all()->count(),
    'instance' => Valeur::where('etat', 1)->count(),
    'deposer' => Valeur::where('etat', 2)->count(),
    'encaisse' => Valeur::where('etat', 3)->count(),
    'retourne' => Valeur::where('etat', 4)->count(),
]);

然后您将能够像
$details->get('total')一样访问它
$details['total']

@HamzaGhaissi I添加了一个额外的访问器选项。你可以使用你喜欢的任何东西。@HamzaGhaissi我添加了一个额外的访问器选项。你可以用你喜欢的任何东西。