Search code examples
phpif-statementrequestternarylaravel-7

PHP error: Unparenthesized `a ? b : c ? d : e` is deprecated


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.


Solution

  • 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' : '' ) }}">