1

Hi I'm stuck on this error message. I tried to encapsulate it with parenthesis still I got an error on this specific line.

   <li class="{{ (\Request::is('stocks/*') ? ' open' : Request::is('stocks') ? ' open' : Request::is('defective/*') ? ' open' : '')  }}">

It works on local, yet after Iv'e deployed it to heroku the error occurs.

Kevin
  • 315
  • 2
  • 5
  • 19
  • 1
    Quick note: from https://www.php.net/manual/en/language.operators.comparison.php: "_It is recommended that you avoid "stacking" ternary expressions. PHP's behaviour when using more than one ternary operator within a single statement is non-obvious_" – brombeer May 11 '20 at 06:03
  • 1
    You need to think about how these parts of the expression are grouped together, this is not just for the system to work it out, but also for the poor developer after you which has got to maintain this code. – Nigel Ren May 11 '20 at 06:08

1 Answers1

2

It looks like you put the parentheses in the wrong place. Try this:

<li class="{{ (\Request::is('stocks/*') ? ' open' : ( Request::is('stocks') ? ' open' : ( Request::is('defective/*') ? ' open' : '' ) ) ) }}">

You also may be able to simplify it:

<li class="{{ ( ( \Request::is('stocks/*') || Request::is('stocks') || Request::is('defective/*') ) ? ' open' : '' ) }}">
kmoser
  • 8,780
  • 3
  • 24
  • 40