1

I want to set active class to my active routes, i have tried below approach but it is not working

The navside.blade.php page

<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>

And my routes are

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');

});

I did tried some different approaches like

  1  {{ Request::segment(1) === 'programs' ? 'active' : null }}

  2  class="@if(Request::url()== url('/home') active @endif"

but they din't work ether

thank you

Mr Robot
  • 887
  • 4
  • 18
  • 47

1 Answers1

3

You can try: (Route::current()->getName() == 'routename') ? 'active' : null

You also can make it a helper function instead of copy pasting the full if statement.

Joeri
  • 151
  • 1
  • 8
  • well this works, thank yo for your time really appreciate it, and what about dynamic routes like `order/{id}` – Mr Robot Jul 18 '17 at 10:57
  • 1
    They will have route names as well if you use `Route::resource()` it will be `orders.show` but in your case it is `orderDetails` you can check all the names with the console command `php artisan route:list` – Joeri Jul 18 '17 at 11:01