Search code examples
htmllaravellaravel-8laravel-9

how to set in laravel blade the display of a tag p depending on whether the data passed has a value or is empty or null


As already described, I want to display the input in my show depending on whether the data present in the view has a value (so it is shown to me through a p tag) or do not show this p tag if the present data is null or empty.

If it is empty or null do not show anything

This is my code:

<div>
    <h4>Code</h4>
    <p>{{$client->code}}</p>
</div>

Solution

  • If I understand your question correctly, the simplest way would be to wrap it in an if statement:

    <div>
        <h4>Code</h4>
        @if(!empty($client->code))
            <p>{{ $client->code }}</p>
        @endif
    </div>