I have 4 classes, how to check if one of them is empty, let's say a text-video
, then do not display, but show the next one immediately
<div class="blocks">
@foreach($article_blocks as $article_block)
<div class="text-image">
<h2>{{ $article_block->title_1 }}</h2>
<h3>{{ $article_block->text_1 }}</h3>
<img src="{{ $article_block->main_image }}" alt="">
</div>
<div class="text-video">
<h3>{{ $article_block->text_1 }}</h3>
<h3>{{ $article_block->video_link }}</h3>
</div>
<div class="carusel">
@foreach($article_block_images as $article_block_image)
<img src="{{ $article_block_image->main_image }}" alt="">
@endforeach
</div>
<div class="text-text">
<h3>{{ $article_block->text_1 }}</h3>
<h3>{{ $article_block->text_2 }}</h3>
</div>
@endforeach
</div>
CodePudding user response:
Just check if it is empty or not.
@foreach($article_blocks as $article_block)
@if(!empty($article_block->text_1))
@endif
<div class="blocks">
@foreach($article_blocks as $article_block)
@if(!empty($article_block->text_1))
<div class="text-image">
<h2>{{ $article_block->title_1 }}</h2>
<h3>{{ $article_block->text_1 }}</h3>
<img src="{{ $article_block->main_image }}" alt="">
</div>
<div class="text-video">
<h3>{{ $article_block->text_1 }}</h3>
<h3>{{ $article_block->video_link }}</h3>
</div>
<div class="carusel">
@foreach($article_block_images as $article_block_image)
<img src="{{ $article_block_image->main_image }}" alt="">
@endforeach
</div>
<div class="text-text">
<h3>{{ $article_block->text_1 }}</h3>
<h3>{{ $article_block->text_2 }}</h3>
</div>
@endif
@endforeach
</div>
simply modify this code based on what you needed.
CodePudding user response:
You can use @empty or @isset. It depends on what you are looking for. If you want to know if a variable is empty, use empty. empty also checks if the variable has been set at all. if you want to know if something is set or not, use isset.
In your case i think empty will do this job:
@empty(! $article_block->text_1) show the block @endempty