benjy / tap
Installs: 3 172
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2025-03-19 09:17:02 UTC
README
composer require benjy/tap
Usage
Without a callback:
$person = new Person();
tap($person)
->update(['name' => 'Ben'])
->save();
With a callback:
$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
Credits
The original concept for this method comes from Ruby. https://ruby-doc.org/core-2.2.3/Object.html#method-i-tap
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
License
This library is open-sourced software licensed under the MIT license.