1
It has a function in Laravel’s ORM that makes the LIMIT
of Mysql.
Which is the Take
and the Skip
.
I’m going to do three Owl Sliders on the page, one under the other. And the images I’m going to put comes from a table in the database. I want all three rides to have the same amount of footage.
So I thought I’d do it like this:
Total de Registros / 3
But this can occur a tithe, for example:
10 / 3 = 3,3333333333333333
But to fix it I make one floor
in PHP and it rounds to 3.
Then there would be 3 in one line, 3 in another line and 3 in another line. But there was a missing image that I want to appear in the last line.
The logic would be:
$result = floor($countWorks / 3);
$slider_1 = Works::take($result)->get();
$slider_2 = Works::take($result)->skip($result)->get();
$slider_3 = Works::take($result)->skip($result + $result)->get();
I just want to know this:
1 - There is another way to do this or this is the best way ?
Owl Slider works like this:
<?php
$works = R::find('works', 'status = 1');
$take = array_chunk($works, 3);
foreach($take as $work){
?>
<div class="owl-slider-works">
<?php
foreach($work as $val){
?>
<div class="item">
<img src="images/works/<?=$val->capa?>" alt="<?=$val->titulo?>">
<div class="titulo">
<h5><?=$val->titulo?></h5>
</div>
</div>
<?php
}
?>
</div>
<?php
}
?>
You need to stay that way inside foreach
. But I don’t understand how chunk
will work to do this. How would it be ?
That’s interesting. I didn’t know this method
chunk
. But let me ask you something... I’ll edit my question.– Diego Souza
is not working. I put 10 photos... and he printed 4 lines, 3 lines with 3 photos and 1 line with 1... ie 4 lines. I want only 3 lines and the rest... ie 4, 4 and 2... Rsrsrs
– Diego Souza
I upgraded the code to my pole...
– Diego Souza
Must be something wrong with my foreach
– Diego Souza
I solved! I told you yesterday that I had to take the total and split it three ways... and you said, "No... son, Chunk does it alone... nhenhe"... so I gave him a good one.
– Diego Souza
Thanks for the help
– Diego Souza