在网络应用程序中,我有一个按 ASC/DESC 顺序对数据进行排序的链接。我希望我的链接首先处于默认状态,当第一次点击时,它将按 ASC 顺序对数据进行排序,如果再次点击,它将使其成为 DESC 顺序。
http//localhost/master/branch/
- 默认网址
http//localhost/master/branch/?sort=name&dir=asc
- 用户第一次点击链接
http//localhost/master/branch/?sort=name&dir=desc
- 再次单击相同的链接
我需要根据 deafult/asc/desc 命令修改链接的图标。我在 anchor 标记中添加了以下条件,但看起来不起作用:
<a href="{{ route('branch.index') }}?sort=name&dir={{ Request::input('dir') == 'asc' ? 'desc' : 'asc' }}">Name</a> <i class="fa fa-{{ !Request::input('dir') ? 'sort' : '(Request::input('dir') == 'asc' ? sort-alpha-asc' : 'sort-alpha-desc'.' }}"></i>
但是上面给出了FatalErrorException
并说syntax error, unexpected 'dir' (T_STRING)
请告知如何在一行中添加多个条件?
最佳答案
您的代码中有多余的'
和.
,或者您可以将它们转义。你可以试试这个,
<a href="{{ route('branch.index') }}?sort=name&dir={{ Request::input('dir') == 'asc' ? 'desc' : 'asc' }}">Name</a>
<i class="fa fa-{{ !Request::input('dir') ? 'sort' : (Request::input('dir') == 'asc' ? 'sort-alpha-asc' : 'sort-alpha-desc') }}"></i>
关于php - Laravel:Laravel Blade 中单行的多个 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44562062/