PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

[FIXED] How to make li class active dynamically in laravel?

 March 03, 2022     laravel, laravel-5, php     No comments   

Issue

My HTML code is

   <div id="sidebar"><a href="#" class="visible-phone"><i class="icon icon-home"></i>Dashboard</a>
        <ul>
          <li class="active"><a href="{{route('ScamType.index')}}"><i class="icon icon-home"></i> <span>Scam Type</span></a> </li>
          <li> <a href="{{route('ScamDatabase.index')}}"><i class="icon icon-signal"></i> <span>Scam Database</span></a> </li>
          <li> <a href="{{route('ScamStory.index')}}"><i class="icon icon-inbox"></i> <span>Scam Story</span></a> </li>
          <li><a href="{{route('KeyWord.index')}}"><i class="icon icon-th"></i> <span>Keyword</span></a></li>
          <li><a href="{{route('Category.index')}}"><i class="icon icon-th"></i> <span>Category</span></a></li>
          <li><a href="{{route('SubCategory.index')}}"><i class="icon icon-th"></i> <span>Sub Category</span></a></li>
</ul>
</div>

Here i gave li class active as like in bootstrap and its not working, but i don't know how to give in laravel and i am very beginner of laravel, so please avoid minus votes and give me the right solution for it.. How Should i change my code to get li class active dynamically?


Solution

You can use ternary operator. For example, you can check URI for the current route:

<li{{ request()->is('scam-types') ? ' class="active"' : '' }}>

You can also use * as wildcard:

<li{{ request()->is('scam-type-number-*') ? ' class="active"' : '' }}>

Or you can check route name:

<li{{ request()->route()->getName() === 'ScamType.index' ? ' class="active"' : '' }}>


Answered By - Alexey Mezenin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing