阅读(1999) (6)

Laravel 8 tap() {#collection-method}

2021-07-01 15:42:07 更新

tap 方法将给定的回调函数传入该集合,允许你在一个特定点「tap」集合,并在不影响集合本身的情况下对集合项执行某些操作:

collect([2, 4, 3, 1, 5])
    ->sort()
    ->tap(function ($collection) {
        Log::debug('Values after sorting', $collection->values()->all());
    })
    ->shift();

// 1