Skip to content

Instantly share code, notes, and snippets.

@mustafaaloko
Created March 22, 2019 17:54
Show Gist options
  • Select an option

  • Save mustafaaloko/a4c7cfc533d6e6664bf594437be0292e to your computer and use it in GitHub Desktop.

Select an option

Save mustafaaloko/a4c7cfc533d6e6664bf594437be0292e to your computer and use it in GitHub Desktop.
Macro in AppServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Collection;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
Collection::macro('evens', function() {
return $this->filter(function($value) {
return $value % 2 === 0;
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment