M
M
mrguseynov2022-03-16 22:55:51
Laravel
mrguseynov, 2022-03-16 22:55:51

How to print array received from Laravel database by 2 instances?

You need to display the news in this order, i.e.

<div class="row">
   <div class="item">
      <div class="title">Title 1</div>
      <div class="text">Text 1</div>
   </div>
   <div class="item">
      <div class="title">Title 2</div>
      <div class="text">Text 2</div>
   </div>
</div>
<div class="row">
   <div class="item">
      <div class="title">Title 3</div>
      <div class="text">Text 3</div>
   </div>
   <div class="item">
      <div class="title">Title 4</div>
      <div class="text">Text 4</div>
   </div>
</div>

but it turns out like this:
<div class="item">
      <div class="title">Title 4</div>
      <div class="text">Text 4</div>
   </div>
<div class="item">
      <div class="title">Title 4</div>
      <div class="text">Text 4</div>
   </div>
<div class="item">
      <div class="title">Title 4</div>
      <div class="text">Text 4</div>
   </div>
<div class="item">
      <div class="title">Title 4</div>
      <div class="text">Text 4</div>
   </div>

I do everything Laravel. Maybe someone knows how to implement the plan. If we would rebuild the resulting array two by two and print it through forich in forich. Looked at the laravel helpers, but did not find the answer

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2022-03-16
@mrguseynov

https://laravel.com/docs/8.x/collections#method-chunk

P
pLavrenov, 2022-03-17
@pLavrenov

1) Laravel chunk
2) Css grid
3) In foreach close and open div.row on every second element. (easy way)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question