PHP错误:无括号`a吗? b:c? d:e`已过时

问题描述 投票:0回答:1

[嗨,我被此错误消息困扰。我尝试用括号将其封装,但在此特定行上仍然出现错误。

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

它在本地运行,但是在将其部署到heroku之后,会发生错误。

php if-statement request ternary laravel-7
1个回答
0
投票

好像您将括号放在错误的位置。试试这个:

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

您也可以简化它:

<li class="{{ ( ( \Request::is('stocks/*') || Request::is('stocks') || Request::is('defective/*') ) ? ' open' : '' ) }}">
© www.soinside.com 2019 - 2024. All rights reserved.