gpt4 book ai didi

php - Laravel Blade 通过@include 使用字符串传递变量会导致错误

转载 作者:IT王子 更新时间:2023-10-28 23:56:41 25 4
gpt4 key购买 nike

在 Laravel 5.0.27 中,我包含一个带有变量的 View 和以下代码:

@include('layouts.article', [
'mainTitle' => "404, page not found",
'mainContent' => "sorry, but the requested page does not exist :("
])

我收到以下错误...

FatalErrorException syntax ... error, unexpected ','

我已经缩小范围,错误仅来自“mainContent”变量字符串中的“(”,当我删除“(”时,错误消失并且一切运行正常。我在文档中找不到任何内容关于此错误或在线列出的任何类似错误。

有谁知道这是预期行为还是应该报告的错误?

非常感谢您的宝贵时间!

最佳答案

这不是错误,而是正则表达式对 blade 语法的限制。解决方案来自 github :

The problem is using multi-line. You can only use a single line to [pass variables] in Blade, since syntax is limited [by regular expressions]

Try the code below and you should be good to go:

@include('layouts.article', ['mainTitle' => "404, page not found", 'mainContent' => "sorry, but the requested page does not exist :("])

关于php - Laravel Blade 通过@include 使用字符串传递变量会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29739745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com