@if inside @foreach where is the error?


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)
  @foreach($product->fphoto as $produ)
  <a href="{{ route('products.show', $product->id) }}">
            <img  src="{{asset('img/profile.jpg')}}" alt="">
                  <a href="{{ route('products.show', $product->id) }}">
              <img  src="{{ $produ->photo }}" alt="">

            <h3>{{ $product->nombreyape }}</h3></a>
asked by Lendy Rodriguez Silva 21.10.2018 в 19:07

1 answer


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


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

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