Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 382
niko craft Avatar asked Oct 15 '25 20:10

niko craft


1 Answers

Laravel or operator was changed in laravel 5.7 to ??

The or Operator Likelihood Of Impact: High

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

try this:

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

here is the upgrade guide.

like image 127
Kapitan Teemo Avatar answered Oct 18 '25 16:10

Kapitan Teemo