如何从Laravel中的$ lookup打印刀片中的值

时间:2019-10-31 06:36:58

标签: laravel mongodb lookup

我在MongoDB中有两个集合,我想在它们之间进行聚合,效果很好,但是我不知道如何在其他集合中的级别的刀片(视图)中打印值?

$allRanges = Range::raw(( function($collection) {  
    return $collection->aggregate([
            [
                '$lookup' => [
                'from' => 'Levels',
                'localField' => 'LevelId',
                'foreignField'=> '_id',
                'as' => 'levels'
            ]
        ], [
            '$match' =>[
                'PlanTypeId'=> '5daad2c12939b70f0b7ff052'
            ]
        ],
    ]);
})))->toarray();

输出:

=> [
        [
            "_id" => "5daad809095e6f0c7e37fbf2",
            "PlanTypeId" => "5daad2c12939b70f0b7ff052",
            "LevelId" => "5dab14832d31e850ea1644b2",
            "Range" => "range1",
            "step" => 1,
            "part" => 10,
            "levels" => MongoDB\Model\BSONArray {#3149
                flag::STD_PROP_LIST: false,
                flag::ARRAY_AS_PROPS: false,
                iteratorClass: "ArrayIterator",
                storage: [
                MongoDB\Model\BSONDocument {#3146
                    flag::STD_PROP_LIST: false,
                    flag::ARRAY_AS_PROPS: true,
                    iteratorClass: "ArrayIterator",
                    storage: [
                        "_id" => MongoDB\BSON\ObjectId {#3147
                            +"oid": "5dab14832d31e850ea1644b2",
                        },
                        "PlanTypeId" => "5daad2c12939b70f0b7ff052",
                        "Level" => "1",
                    ],
                },
            ],
        },
    ],

我得到了Range,但是如何获得例如level-> Level?

<tr>
    @foreach($allRanges as $d)

    <td>{{$d['Range']}}</td>
</tr>

@endforeach

0 个答案:

没有答案