php - 包含 url 参数的 Laravel 事件菜单项

标签 php laravel

我试图在我的列表项中设置事件类,但它不起作用。

我在 Blade 中的代码:

@foreach($data as $site)
  <ul class="sidebar-menu" id="second-menu">
  @if(isAdmin())<li class="{{-- active class  for url parameter --}}"><a href="{{ url('sites/'.$site->id.'/edit') }}" >{{ $site->name }}</a></li>
@endif
</ul>
@endforeach

所以,如果我写: li class="@if(getRouteName() == 'site@index'){{ 'active' }}@endif",效果很好,但在我的例子中,问题是我想在 foreach sites/'.$site->id.'/edit

中获取 'active'

非常感谢。

最佳答案

使用 is()方法。例如:

<li class="{{ request()->is('sites/*/edit') ? 'active' : '' }}"

关于php - 包含 url 参数的 Laravel 事件菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43937494/

相关文章:

php - 在 MySQLi 中使用 "begin_transaction"方法有什么好处?

php - 默认情况下 Apache 2 gzip json 输出吗?

PHP 和 SQL 哈希帮助 : What am I doing wrong?

php - Laravel 使用关系显示 View ,加入

laravel - Laravel 的多态关系也适合真正的多态吗?

php - 正则表达式匹配字母数字,中间可能只有破折号

mysql - 无法连接 - 无效设置

php - 创建后 Laravel 5 Eloquent 加载模型属性

php - 如何在 Laravel 5 中使用我的包

php - WordPress:以正确的顺序覆盖子主题中的多个 css 文件