Laravel SEP Google json 数据参考 mysql db

Laravel SEO Google json data with refering to mysql db

我正在尝试改进我们 Laravel 项目中的 SEO,我们从名为 "slug".

的数据库中获取 url 的数据。

目前遇到的问题是此代码无法正常工作:

<script type="application/ld+json">
    {
        "@context":"http://schema.org",
        "@type":"Restaurant",
        "url":"https://test.com/"{{$restaurant['slug']}},
        "priceRange":"$$",
        "@id":"https://test.com/"{{$restaurant['slug']}},
        "name":{{$restaurant['name']}},
        "address": {
            "@type":"PostalAddress",
            "streetAddress":{{$restaurant['address']}},
            "addressLocality":{{$restaurant['city']}},
            "addressRegion":{{$restaurant['city']}},
            "postalCode":{{$restaurant['zip']}},
            "addressCountry":"Switzerland"
            }
    }
</script>

得到的错误如下: "Undefined variable: restaurant"

有人可以帮忙吗?

您需要像这样用双引号引起来:

"{{$restaurant['address']}}"