Zach Handley Zach Handley - 1 month ago 17
PHP Question

Adding a Variable to Laravel Request

I'm trying to make an Active-Navbar on my website, however in one category of my navbar it is dynamically generated and I can't seem to figure out how to put a variable in to check the request

Here's the code I have:

@foreach( Auth::user()->getTests() as $Test )
<li {{ (Request::is('/test/'.$Test->id.'/*') ? "class=nav-active" : '') }}>
<a href="{{URL("/test/$Test->id/view/")}}">
{{$Test->name}}
</a>
</li>
@endforeach


I've tried putting double quotes in (as PHP sees variables with double quotes), but it still doesn't seem to work. The desired outcome can be seen here

http://preview.oklerthemes.com/?theme=PortoAdmin

I just have a list of dynamically generated test names that I'd like to be the active item when they are selected.

Thanks!


  • Zach



EDIT: There seems to be some confusion, I was referencing this line:

<li {{ (Request::is('/test/'.$Test->id.'/*') ? "class=nav-active" : '') }}>


I've also tried

<li {{ (Request::is("/test/$Test->id/*") ? "class=nav-active" : '') }} >

Answer

Try removing the first slash

<li "{{ Request::is('test/'.$Test->id.'/*') ? "class=nav-active" : "" }}" >