我想将active
类设置为我的活动路线,我尝试过以下方法,但它无法正常工作
navside.blade.php
页面
<ul class="sidebar-menu collapsible collapsible-accordion" data-collapsible="accordion">
<li class="no-padding {{ Request::is('/manager/dashboard') ? 'active' : '' }}">
<a class="waves-effect waves-grey" href="{!! URL::asset('/manager/dashboard')!!}">
<i class="material-icons">settings_input_svideo</i>Dashboard
</a>
</li>
<li class="no-padding {{ Request::is('/manager/orders') ? 'active' : '' }}">
<a class="waves-effect waves-grey" href="{!! URL::asset('/manager/orders')!!}">
<i class="material-icons">shopping_cart</i>Orders
</a>
</li>
<li class="no-padding {{ Request::is('/manager/outlets') ? 'active' : '' }}">
<a class="waves-effect waves-grey" href="{!! URL::asset('/manager/outlets')!!}">
<i class="material-icons dp48">store</i>Outlets
</a>
</li>
<li class="no-padding {{ Request::is('/manager/reports') ? 'active' : '' }}">
<a class="waves-effect waves-grey" href="{!! URL::asset('/manager/reports')!!}">
<i class="material-icons dp48">receipt</i>Reports
</a>
</li>
<li class="no-padding {{ Request::is('/manager/manage') ? 'active' : '' }}">
<a class="waves-effect waves-grey" href="{!! URL::asset('/manager/manage')!!}">
<i class="material-icons dp48">input</i>Manage
</a>
</li>
</ul>
我的路线是
Route::group(['prefix' => 'manager', 'middleware' => ['auth','roles'], 'roles' => 'manager'], function() {
Route::get('/dashboard', 'ManagerController@index')->name('dashboard');
Route::get('/orders', 'OrdersController@index')->name('orders');
Route::get('/orders/{order_id}', 'OrdersController@show')->name('orderDetails');
Route::post('/assign_orders', 'OrdersController@assignDeliveryBoy')->name('assignOrder');
Route::get('/outlets', 'OutletsController@index')->name('outlets');
Route::get('/reports', 'ReportsController@index')->name('reports');
});
我确实尝试了一些不同的方法,比如
1 {{ Request::segment(1) === 'programs' ? 'active' : null }}
2 class="@if(Request::url()== url('/home') active @endif"
但他们没有工作以太
谢谢
答案 0 :(得分:3)
您可以尝试:
(Route::current()->getName() == 'routename') ? 'active' : null
您也可以将其作为辅助函数,而不是复制粘贴完整的if语句。