3

I am new in Laravel, I'm trying to give active class to menu links if current url matches the menu link url,

<li @if (Request::is('student/lecture') || Request::is('admin/lecture/*')) class="active" @endif >
    <a href="{{ url('student/lecture') }}"><i class="fa fa-globe"></i>Lectures </a>
</li>

Its working for student/lecture or student/lecture/* , but its not wokring for student/lecture/13?id=30 ( without sending id in get it work, but its not working when id is passed).

MilanPanchal
  • 2,943
  • 1
  • 19
  • 37
Asad Zaheer
  • 81
  • 2
  • 9
  • I think http://stackoverflow.com/questions/17591181/how-to-get-the-current-url-inside-if-statement-blade-in-laravel-4 will give you your answer. – Mark Davidson Oct 29 '15 at 11:33
  • `Request::is` doesn't match GET parameters. Only route itself. – Maxim Lanin Oct 29 '15 at 11:55
  • thank you for help @MarkDavidson i found a work around in your provided link , just added `Route::current()->getName() == 'student.lecture.show'` – Asad Zaheer Oct 30 '15 at 07:38

2 Answers2

0

Try the following:

<li{!! (Request::is('student/lecture') || Request::is('admin/lecture/*') ? ' class="active"' : '') !!}>
    <a href="{{ url('student/lecture') }}"><i class="fa fa-globe"></i>Lectures </a>
</li>
Peter Kota
  • 8,048
  • 5
  • 25
  • 51
0

Simply use this one:

Request::is('user-wallet*')

Instead of this one:

Request::is('user-wallet/*')

The slash before the astrix will make the difference.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77