Laravel Helper Set Class Active Not Working

445 Views Asked by At

I have a helper function.

function setActive($path, $active = 'active')
{
    return call_user_func_array('Request::is', (array)$path) ? $active : '';
}

When I go to the site: http://example.net/posts?group=active, my function is not working and returns an empty string ("").

I use this in my Blade:

class="{{ setActive(['posts?group=active'] }}"

How can I resolve this?

1

There are 1 best solutions below

0
On

Is this for navigation? You don't need a helper function to achieve that. In your blade, you can just do...

@if(request()->is() === 'posts')

OR

{{ request()->is('posts') ? 'active' : '' }}