Andrei Nagy
Andrei Nagy

Reputation: 251

How to hide an icon if the link is empty

I want to hide an icon if the link is empty. Here is the <a> tag with <i> tag for Instagram. If the field from admin is empty, I want to hide it. I'm using the Laravel framework.

 <a href="https://instagram.com/{{ $model->instagram }}"><i class="fa fa-instagram"></i>&nbsp;&nbsp;{{ $followed_by }}</a> 

Do you have any ideas?

Thanks.

Upvotes: 2

Views: 419

Answers (2)

d3jn
d3jn

Reputation: 1410

You can use @if blade directive:

@if ($model->instagram)
    <a href="https://instagram.com/{{ $model->instagram }}">
        <i class="fa fa-instagram"></i>&nbsp;&nbsp;{{ $followed_by }}
    </a>
@endif

Depending on your Laravel version you might also have @isset/@empty directives available for you. You can read more about it in official documentation.

Upvotes: 4

Karan Sadana
Karan Sadana

Reputation: 1373

Use Blade @if Statement.

Simply Write like below code:-

@if(!empty($model->instagram))
<a href="https://instagram.com/{{ $model->instagram }}"><i class="fa fa-instagram"></i>&nbsp;&nbsp;{{ $followed_by }}</a>
@endIf

That's It.

You can read about more laravel Blade from here

Upvotes: 1

Related Questions