不能用??在 blade 模板中,Laravel

Can't use ?? in blade template, Laravel

这段代码是我写的 <p>{{ $name or 'hello' }}</p>, 但它 return 只是 1。我读到,它是 Laravel 5.7 中使用的语法,而不是更高,并将我的代码更改为此 <p>{{ $name ?? 'hello' }}</p>。 但是这段代码return什么都没有。请帮助我。

改为使用三元运算符

<p>{{ $name ?: 'hello' }}</p>

??null 合并运算符,在您的情况下 $name 不是空字符串,而是空字符串。

https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary