Permalink
Browse files

新增 Collection::macro(), subset()

  • Loading branch information...
1 parent 9fa92fb commit 31983807ab1c69261858d9c1a0217f3a4e3032e5 @oomusou committed Jul 8, 2016
Showing with 9 additions and 1 deletion.
  1. +9 −1 app/Providers/AppServiceProvider.php
@@ -2,6 +2,7 @@
namespace App\Providers;
+use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@@ -23,6 +24,13 @@ public function boot()
*/
public function register()
{
- //
+ Collection::macro('pick', function ($columns) {
+ return collect($this->items)->map(function ($value) use ($columns) {
+ return collect($columns)
+ ->map(function ($column) use ($value) {
+ return $value->$column;
+ })->all();
+ });
+ });
}
}

0 comments on commit 3198380

Please sign in to comment.