Laravel 5.7 (Blade) - Ternary operator on two levels is not working

Asked

Viewed 1,146 times

0

The following code works:

if($cc->is_removed){
    $status = 'Removed';
}
elseif (! $cc->isActive){
    $status = 'Inactive';
}
elseif ($cc->isActive){
    $status = 'Active';
}

and on the same page the following code using ternary operators does not work: it never enters the 'Removed'.

{{ $cc->is_removed ? 'Removed' : !$cc->isActive ? 'Inactive' : 'Active' }}

Where am I going wrong?

1 answer

2


I believe your error is related to not having a parentheses split, here’s a way to resolve this:

{{ $cc->is_removed ? 'Removed' : (!$cc->isActive ? 'Inactive' : 'Active') }}

This may take the form in which Lade compiles.

  • It works. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.