[英]Can't use ?? in blade template, Laravel
I wrote this code <p>{{ $name or 'hello' }}</p>
, but it return just 1. I read, that it's syntax used in Laravel 5.7, not higher and change my code to this <p>{{ $name?? 'hello' }}</p>
我写了这段代码
<p>{{ $name or 'hello' }}</p>
,但它只返回 1。我读到,它是 Laravel 5.7 中使用的语法,而不是更高版本,并将我的代码更改为此<p>{{ $name?? 'hello' }}</p>
<p>{{ $name?? 'hello' }}</p>
. <p>{{ $name?? 'hello' }}</p>
。 But this code return nothing.但是这段代码什么都不返回。 Help me, please.
请帮帮我。
Use ternary operator instead改用三元运算符
<p>{{ $name ?: 'hello' }}</p>
??
is null coalescing operator and in your case $name
is not null but empty string.是null合并运算符,在您的情况下
$name
不是 null 而是空字符串。
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.