4 months ago

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']) }}>

...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')}}">

Expected outcome:

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

What am I doing wrong? Thanks

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