Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocraft's avatar

can't use OR in blade template

When I am developing locally on win10 php7.2 nginx expression like this works just fine

    <div class="{{ $menuclass or 'menu'}}">

which gives

    <div class="menu">

but as soon as I deploy it via laravel forge to ubuntu machine it fails to work and I get this

    <div class="1">

It seems that instead of doing this:

    isset($menuclass ) ? $menuclass : 'menu'

it just returns 1

Any ideas why?

This feature was blogged about here: https://laravel-news.com/blade-or-operator

Has it been deprecated in later versions of laravel?

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

or has been removed from later versions as you can just use php null coalesce operator instead ??

Check the upgrade guide

1 like
manelgavalda's avatar

Quoting https://laravel.com/docs/5.7/upgrade:

The Blade "or" operator has been removed in favor of PHP's built-in ?? "null coalesce" operator, which has the same purpose and functionality:

// Laravel 5.6... {{ $foo or 'default' }}

// Laravel 5.7... {{ $foo ?? 'default' }}

1 like

Please or to participate in this conversation.