Installation
composer require benjy/tap
Usage
Without a callback:, (*1)
$person = new Person();
tap($person)
->update(['name' => 'Ben'])
->save();
With a callback:, (*2)
$person = new Person();
tap($person, function ($person) {
$person->update(['name' => 'Ben'])
$person->save();
});
Way more useful examples here: https://mattstauffer.co/blog/introducing-laravels-tap-higher-order-tap-and-collection-tap, (*3)
Credits
The original concept for this method comes from Ruby.
https://ruby-doc.org/core-2.2.3/Object.html#method-i-tap, (*4)
This code was taken straight from the Laravel framework where I initially discovered this concept. I wanted to use it
in other applications so I broke it out into a separate library. Thanks to Laravel, (*5)
License
This library is open-sourced software licensed under the MIT license., (*6)