Cvetan's avatar

Blade null coalesce doesn't work

As said in the title, when i use or keyword in blade template, i get variable undefined variable error. Here is the example: {{ $title or 'Default page title' }}

Why this doesn't work? It is in Laravel docs. PHP 7.2, Laravel 5.7. Am i missing something?

0 likes
4 replies
wilburpowery's avatar
Level 23

The or helper is been removed in 5.7.

You should use the Null Coalesce Operator: ??

So you'll be left with {{ $title ?? 'Default page title' }}

3 likes
saluei's avatar

problem with coalesce in blade I have these line in blade file

{{$EntObj->$GroupFieldName}}

{{ $EntObj->$GroupFieldName ?? 'not defined' }}

{{$EntObj->$GroupFieldName}} exist and have value but always coalesce return 'not defined' ???

thank you

Please or to participate in this conversation.