Skip to content

Instantly share code, notes, and snippets.

@mustafaaloko
Last active March 22, 2019 17:47
Show Gist options
  • Save mustafaaloko/faec02c969b9e40e242eac0b1855a60d to your computer and use it in GitHub Desktop.
Save mustafaaloko/faec02c969b9e40e242eac0b1855a60d to your computer and use it in GitHub Desktop.
Laravel Macro Example
<?php
use Illuminate\Support\Collection;
Collection::macro('evens', function() {
return $this->filter(function($value) {
return $value % 2 === 0;
});
});
// Now the above can be used as below:
$collection = collect([3, 5, 8, 2, 1, 6]);
$collection->evens();
// [8, 2, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment