master

laravel/framework

Last updated at: 29/12/2023 09:25

Tappable.php

TLDR

The Tappable trait provides a method called tap that allows the user to call a closure with the current instance and then return the instance.

Methods

tap

This method accepts a closure as an argument and calls it with the current instance. It then returns the instance.

Classes

None

<?php

namespace Illuminate\Support\Traits;

trait Tappable
{
    /**
     * Call the given Closure with this instance then return the instance.
     *
     * @param  callable|null  $callback
     * @return $this|\Illuminate\Support\HigherOrderTapProxy
     */
    public function tap($callback = null)
    {
        return tap($this, $callback);
    }
}