I
I
Ivan Ivanov2019-03-10 15:47:39
Laravel
Ivan Ivanov, 2019-03-10 15:47:39

How to iterate over multiple arrays at once in php?

There is a task: It is necessary to display data, photos, as well as likes and dislikes (number) on the page with photos.
I write on Laravel (5.5)
Displayed everything except likes / dislikes. There is a problem with this. Two arrays $likes and $dislikes are sent to the page through the controller, photos are sorted through foreach(). I tried to make another foreach (which is for pictures) inside foreach (which is for likes), but in the end, the likes just got over, I also tried foreach (which is for likes) to raise it to a level higher than foreach (for photos), then the photos are duplicated, and even so it will output incorrectly
Output image:

@foreach($images as $image)
{{$image->id}}
  <img height="100px" width="100px" src="/storage/{{$image->photos_name}}">
  <br>
  <form method="post">
  {{csrf_field()}}
    <button type="submit" name="like_photo" value="yes">Нравится фото</button>
    <input type="hidden" name="photo_id" value="{{$image->id}}">
    <button type="submit" name="like_photo" value="no">Не нравится фото</button>
  </form>
  <br>
  <hr>
@endforeach

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question