Laravel dynamic HTML tag name, based on if href is passed

Viewed 170

I have a laravel component

<x-link :href="{{ $href }}">
    some text
</x-link>

If I don't pass $href prop I want to print span tag instead, without duplicating code, but on tag directly.

Something like this that exists in Vue.js would be nice:

<component :is="href ? 'a' : 'span'">
    some text
</component>
1 Answers

You could make a new component containing your span and conditionally render it...

@if($href)
<x-link :href="{{ $href }}"> some text </x-link>
@else
<x-new-component>
some text
</x-new-component>
@endif
Related