@if inside @foreach where is the error?

2

Where is the error? when the empty variable is full it works perfect but when it comes empty it does not show me the other part neither the image nor the link where the error can be ??

@foreach($products as $product)
<div>
  @foreach($product->fphoto as $produ)
@if(empty($produ->id))
  <a href="{{ route('products.show', $product->id) }}">
            <img  src="{{asset('img/profile.jpg')}}" alt="">
              @else
                  <a href="{{ route('products.show', $product->id) }}">
              <img  src="{{ $produ->photo }}" alt="">

      @endif
      @endforeach
            <h3>{{ $product->nombreyape }}</h3></a>
            <p>Textop>
          </div>
        @endforeach
    
asked by Lendy Rodriguez Silva 21.10.2018 в 19:07
source

1 answer

2

If you want to control if the arrangement is full or not and send a message accordingly; you should do it through a forelse

EXAMPLE

@forelse($posts as $post)
    <h1>{{ $post->title }}</h1>
@empty
    <small>No existe contenido que mostrar</small>
@endforelse

just after @empty you send the message or the actions that you are going to carry out to indicate that the arrangement is empty and that consequently the user does something

    
answered by 21.10.2018 / 19:11
source