使用Laravel 5.4中的刀片模板命令显示嵌套(多级)阵列中的数据

问题描述 投票:0回答:1

我们正在用clojure和mongodb建立一个庞大的系统。我正在为系统开发一个管理面板。但我正在使用Laravel 5.4(最新版本)。

我设法连接mongodb与PHP和laravel。

这是我的问题。我们的数据库有多级数组。

这是数据库

/* 1 */
{
    "_id" : ObjectId("58def7eb06703609d370f76f"),
    "description" : "Tuxido",
    "publisher" : ObjectId("578bb0f0e403c10f2f490d8f"),
    "title" : "Tux",
    "label" : "Tux",
    "imgs" : [ 
        {
            "url" : "http://localhost:8088/ad/578bb0f0e403c10f2f490d8f-849ca60b06b9f79e337dd29f51f7ed384f205d1e46c68a19af6f3935c167d15a.png"
        }
    ]
}

/* 2 */
{
    "_id" : ObjectId("5908c91e0a975a7b6e97bc24"),
    "description" : "Since the first edition until 1992 ",
    "publisher" : ObjectId("578bb0f0e403c10f2f490d8f"),
    "title" : "National Geographic",
    "imgs" : []
}

/* 3 */
{
    "_id" : ObjectId("5907b0d00a975a7b6e97bc22"),
    "description" : "3 months old kitten",
    "publisher" : ObjectId("578bb0f0e403c10f2f490d8f"),
    "title" : "Bino",
    "imgs" : [ 
        {
            "url" : "http://localhost:8088/ad/578bb0f0e403c10f2f490d8f-31ec293361cf7d318a189b7678841935a404249718d5f6a4d10ee70017aa600a.png"
        }, 
        {
            "url" : "http://localhost:8088/ad/578bb0f0e403c10f2f490d8f-1884915f5d94c6566a9bc329b673b5b525ff09329500c596a3209356006de0e5.png"
        }, 
        {
            "url" : "http://localhost:8088/ad/578bb0f0e403c10f2f490d8f-a1f7b7bbb9cbb89dd7dd61e6aa26a6fde2357f01296ebe47956205858a4f55a3.png"
        }, 
        {
            "url" : "http://localhost:8088/ad/578bb0f0e403c10f2f490d8f-e86c731f23635e86ffb19333bdefba9761a6a2b8cbbc1ffe198acd6f7215e8db.png"
        }
    ]
}

我想获取图片网址并将其显示在标签中。所以我用刀片模板写了这个,

@foreach ($db as $item)
    <div class="divTableRow">
        <div class="divTableCell">&nbsp;</div>
        <div class="divTableCell">&nbsp;</div>
        <div class="divTableCell">{{$item ->title}}</div>
        <div class="divTableCell">{{$item->description}}</div>
        <div class="divTableCell">&nbsp;</div>
        <div class="divTableCell">
            @foreach ($item->imgs as $imgs)
                <img src="{{$imgs->url}}"/>
            @endforeach
        </div>
        <div class="divTableCell">&nbsp;</div>
    </div>
@endforeach

但这给了我两个错误。

ErrorException 1

ErrorException 2

我怎样才能解决这个问题?

php arrays mongodb laravel-5.4 blade
1个回答
0
投票

嗨,伙计们找到了这样做的方法。如果你们中的任何人遇到这种问题

(试图获得非对象的属性)

您可以使用,

{{$ imgs ['url']}}代替{{$ imgs-> url}}

如果数据库看起来像这样,并且您想从状态中获取值,

/* 1 */
{
    "_id" : ObjectId("123432132414657"),
    "status" : {
        "active" : true,
        "approved" : true,
        "submitted" : false,
        "deleted" : false
    }
}

您可以使用..

{{$用品 - >状态[ '活性']}}

© www.soinside.com 2019 - 2024. All rights reserved.