Skip to content

Instantly share code, notes, and snippets.

@abdumu
Created December 23, 2017 04:11
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 abdumu/fcfcbd21e30df980157015c224b546e6 to your computer and use it in GitHub Desktop.
Save abdumu/fcfcbd21e30df980157015c224b546e6 to your computer and use it in GitHub Desktop.
[Laravel] Drop first or last items from a collection
<?php
/**
* drop the first or last {$limit} items.
*
* @param int $limit
* @return Illuminate\Support\Collection
*/
Illuminate\Support\Collection::macro('drop', function(int $limit){
if ($limit < 0) {
return $this->slice(0, $limit);
}
return $this->slice($limit);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment