Skip to content

Latest commit

 

History

History
16 lines (15 loc) · 637 Bytes

tap_into_collection_at_any_point.md

File metadata and controls

16 lines (15 loc) · 637 Bytes

Tap into collection at any point without affecting the original collection

You can "tap" into the results at any point during a set of collection operations without affecting the main collection.

$products->where('price', 100)
    ->tap(function ($productsThatCost100) {
        // Do something with the current collection results
        // without affecting the rest of the pipeline
        dump($productsThatCost100);
    })
    ->where('color', 'blue')
    ->tap(function ($blueProductsThatCost100) {
        // Jump in and out at any point to get different sets of data
        dump($blueProductsThatCost100);
    });