Zach Handley Zach Handley - 7 months ago 61
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" : '') }} >


Try removing the first slash

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