Created
December 23, 2017 04:11
-
-
Save abdumu/fcfcbd21e30df980157015c224b546e6 to your computer and use it in GitHub Desktop.
[Laravel] Drop first or last items from a collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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