Zach Handley Zach Handley - 1 year ago 92
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/")}}">

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

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


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

Try removing the first slash

<li "{{ Request::is('test/'.$Test->id.'/*') ? "class=nav-active" : "" }}" >
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download