Home > database >  Can't use ?? in blade template, Laravel
Can't use ?? in blade template, Laravel

Time:09-30

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>. But this code return nothing. Help me, please.

CodePudding user response:

Use ternary operator instead

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

?? is null coalescing operator and in your case $name is not null but empty string.

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

  • Related