ftina
4 months ago
496
5
Laravel

Laravel 7 components - merge css on conditions

Posted 4 months ago by ftina

Hi, I need a little help here.

I have a navItem component

<a href="#" {{ $attributes->merge(['class' => 'nav-item flex flex-align-center']) }}>
	...
</a>

...and in my blade (nav-menu) file

<x-nav-item class="{{activeLink('/','active')}}" />

activeLink is a helper function:

function activeLink($route, $activeClass = 'active')
{
	return Request::is($route) ? $activeClass : '';
 }

The activeLink function is not evaluated, and in my rendered HTML, I have

<a href="#" class="nav-item flex flex-align-center {{activeLink('/','active')}}">
	...
</a>

Expected outcome:

<a href="#" class="nav-item flex flex-align-center active">
	...
</a>

What am I doing wrong? Thanks

Please sign in or create an account to participate in this conversation.