Skip to content

Instantly share code, notes, and snippets.

@arzola
Last active June 23, 2017 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arzola/bba3efef618da84756b3d10cbdd25ca2 to your computer and use it in GitHub Desktop.
Save arzola/bba3efef618da84756b3d10cbdd25ca2 to your computer and use it in GitHub Desktop.
Refactor to collection
$tweets = Datostwitter::orderBy('hora', 'desc')->take(Settings::get('twitter_max'))->get();
$pagetweets = [];
$total = count($tweets);
$itemtw = [];
for ($i = 0; $i < $total; $i+=5){
for ($n = 0; $n < 5; $n++){
if (isset($tweets[$i+$n])){
$itemtw[$n] = $tweets[$i+$n];
}
}
$pagetweets[$i] = $itemtw;
}
$this->tweets = $pagetweets;
@adamwathan
Copy link

If I'm not mistaken, this will do what you need 👍

$tweets = Datostwitter::orderBy('hora', 'desc')->take(Settings::get('twitter_max'))->get();
$this->tweets = collect($tweets)->chunk(5)->all();

@arzola
Copy link
Author

arzola commented Jun 17, 2016

Thanks, it's perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment