PHPackages                             r3bzya/action-wrapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. r3bzya/action-wrapper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

r3bzya/action-wrapper
=====================

ActionWrapper is a simple and flexible way to decorate your actions.

v1.4.0(1y ago)066MITPHPPHP ^8.2

Since Dec 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/R3bzya/action-wrapper)[ Packagist](https://packagist.org/packages/r3bzya/action-wrapper)[ Docs](https://github.com/R3bzya/action-wrapper)[ RSS](/packages/r3bzya-action-wrapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (8)Used By (0)

Action Wrapper
==============

[](#action-wrapper)

Introduction
------------

[](#introduction)

ActionWrapper is a simple and flexible way to decorate your actions.

Installation
------------

[](#installation)

Via Composer:

```
composer require r3bzya/action-wrapper
```

Publishing
==========

[](#publishing)

The commands below allow you to publish specific components of the package to your Laravel project:

```
php artisan vendor:publish --tag=action-wrapper-config
php artisan vendor:publish --tag=action-wrapper-stubs
```

Available classes
-----------------

[](#available-classes)

When you need to wrap up some actions, and you don't want to create a new class for the action, use the `FluentAction` class. You can create a new instance using the `wrapper` function.

> ***Note:*** The FluentAction class has [extended methods](#extended-methods).
>
> ```
> $action = new \R3bzya\ActionWrapper\Support\FluentAction;
>
> $action->execute(fn(): bool => true);
> ```
>
>
>
> The shortest way:
>
> ```
> wrapper()->execute(fn(): bool => true);
> ```

Available methods
-----------------

[](#available-methods)

### Base methods

[](#base-methods)

> ***Note:*** These methods available in `\R3bzya\ActionWrapper\Support\Traits\Simples\HasActionWrapper`.
>
> ```
> class Example
> {
>    use \R3bzya\ActionWrapper\Support\Traits\Simples\HasActionWrapper;
>
>    ...
> }
> ```

#### *after()*

[](#after)

The `after` method allows you to add a callable function to the ActionWrapper, which will be executed after any of the decorated methods have been called.

```
wrapper()->after(fn(mixed $result): mixed => $result);
```

#### *before()*

[](#before)

The `before` method allows you to add a callable function to the ActionWrapper that will be executed before any of the decorated methods. If the given callable returns false, the action will stop executing. To modify the input arguments, the callable should return an array. Otherwise, the `before` method acts like a tap, executing the callable without changing the input.

```
wrapper()->before(fn(mixed $value): array => [$value]);
```

```
wrapper()->before(fn(...$arguments): array => $arguments);
```

```
wrapper()->before(fn(): bool => false);
```

```
wrapper()->before(function (mixed $value): void {
    //
};
```

#### *forgetActionWrapper()*

[](#forgetactionwrapper)

The `forgetActionWrapper` method unsets the action wrapper from an action.

```
wrapper()->forgetActionWrapper();
```

#### *getActionWrapper()*

[](#getactionwrapper)

The `getActionWrapper` method returns a cached ActionWrapper or creates and caches a new ActionWrapper, then returns.

```
wrapper()->getActionWrapper();
```

#### *makeActionWrapper()*

[](#makeactionwrapper)

The `makeActionWrapper` method creates a new ActionWrapper instance.

```
wrapper()->makeActionWrapper();
```

#### *pipes()*

[](#pipes)

The `pipes` method returns an array of pipes from the ActionWrapper instance.

```
wrapper()->pipes();
```

#### *through()*

[](#through)

The `through` method adds a callable decorator that the action will be sent through.

```
wrapper()->through(fn(array $arguments, \Closure $next): \Closure => $next($attributes));
```

### Extended methods

[](#extended-methods)

> ***Note:*** The next methods available in `\R3bzya\ActionWrapper\Support\Traits\HasActionWrapper`or you can extend the `\R3bzya\ActionWrapper\Support` class.
>
> ```
> class Example
> {
>    use \R3bzya\ActionWrapper\Support\Traits\HasActionWrapper;
>
>    ...
> }
> ```

#### *abortIf()*

[](#abortif)

The `abortIf` method throws an HttpException with the given data if the result is true.

```
wrapper()->abortIf();
```

#### *abortInternalServerErrorUnless()*

[](#abortinternalservererrorunless)

The `abortInternalServerErrorUnless` method throws an HttpException with the given data unless the result is true.

```
wrapper()->abortInternalServerErrorUnless();
```

#### *abortUnless()*

[](#abortunless)

The `abortUnless` method throws an HttpException with the given data unless the result is true.

```
wrapper()->abortUnless();
```

#### *throwableInsteadOfThrow()*

[](#throwableinsteadofthrow)

The `throwableInsteadOfThrow` method returns an exception without throwing.

```
wrapper()->throwableInsteadOfThrow();
```

### *each()*

[](#each)

The `each` method runs each element of the array through an action method by default 'execute'. You can use closure when you need to send multiple elements of a function.

```
wrapper()->each([1, 2, 3]);
wrapper()->each([fn() => [1, 2, 3], fn() => [4, 5]]);
```

#### *log()*

[](#log)

The `log` method is the default method for logging action data. Write the log if the given value is truthy.

> ***Note:*** You can use a custom logger to safe logs to a specific file and other channels.

```
wrapper()->log(function (\R3bzya\ActionWrapper\Contracts\Support\Payloads\Payload $payload) {
    \R3bzya\ActionWrapper\Support\Facades\Log::info('README.md,stack:Payload data', $payload->all());
});
```

#### *logArguments()*

[](#logarguments)

The `logArguments` method logs the action arguments.

```
wrapper()->logArguments('logArguments');
```

#### *logExceptions()*

[](#logexceptions)

The `logExceptions` method logs an exception if an exception occurs.

```
wrapper()->logExceptions('logExceptions');
```

#### *logIfNotDone()*

[](#logifnotdone)

The `logIfNotDone` method logs the action data if an exception was thrown NotDoneException, or if the result is false.

```
wrapper()->logIfNotDone('logIfNotDone');
```

#### *logIfFailed()*

[](#logiffailed)

The `logIfFailed` method logs the action data if an exception was thrown or if the result is not present in the payload.

```
wrapper()->logIfFailed('logIfFailed');
```

#### *logPerformance()*

[](#logperformance)

The `logPerformance` method logs the performance of an action in milliseconds.

```
wrapper()->logPerformance('logPerformance');
```

#### *logResult()*

[](#logresult)

The `logResult` method logs the result of an action. If an exception is thrown during the action, the result will not be logged.

```
wrapper()->logResult('logResult');
```

#### *payload()*

[](#payload)

The `payload` method aggregates action data and sets it in a payload. If you need to change the result, you can change it in the payload using setters.

```
wrapper()->payload(function (\R3bzya\ActionWrapper\Contracts\Support\Payloads\Payload $payload): void {
    //
});
```

#### *payloadWhen()*

[](#payloadwhen)

The `payloadWhen` method applies the given callable to a payload if the given value is truthy.

```
wrapper()->payloadWhen(function (\R3bzya\ActionWrapper\Contracts\Support\Payloads\Payload $payload): void {
    //
}, true);
```

#### *payloadUnless()*

[](#payloadunless)

The `payloadUnless` method applies the given callable to a payload if the given value is falsy.

```
wrapper()->payloadUnless(function (\R3bzya\ActionWrapper\Contracts\Support\Payloads\Payload $payload): void {
    //
}, false);
```

#### *retry()*

[](#retry)

The `retry` method retries an action if it has an exception.

```
wrapper()->retry(1);
```

#### *refreshModel()*

[](#refreshmodel)

The `refreshModel` method reloads the model instance with fresh attributes from the database. [see](https://laravel.com/docs/10.x/eloquent#refreshing-models)

```
wrapper()->refreshModel();
```

#### *falseInsteadOfThrowable()*

[](#falseinsteadofthrowable)

The `falseInsteadOfThrowable` method returns false when an exception is thrown.

```
wrapper()->falseInsteadOfThrowable();
```

#### *tap()*

[](#tap)

The `tap` method calls the given Closure with the action result then returns the action result.

```
wrapper()->tap(function (mixed $result): void {
    //
});
```

#### *tapWhen()*

[](#tapwhen)

The `tapWhen` method calls the given Closure if the given value is truthy then returns the action result.

```
wrapper()->tapWhen(true, function (mixed $result): void {
    //
});
```

#### *tapUnless()*

[](#tapunless)

The `tapUnless` method calls the given Closure if the given value is falsy then returns the action result.

```
wrapper()->tapUnless(false, function (mixed $result): void {
    //
});
```

#### *throwIf()*

[](#throwif)

The `throwIf` method throws the given exception if the result is true.

```
wrapper()->throwIf();
```

#### *throwIfNotDone()*

[](#throwifnotdone)

The `throwIfNotDone` method throws the given exception if the result is false.

```
wrapper()->throwIfNotDone();
```

#### *throwUnless()*

[](#throwunless)

The `throwUnless` method throws the given exception unless the result is true.

```
wrapper()->throwUnless();
```

#### *transaction()*

[](#transaction)

The `transaction` method begins a new database transaction using try/catch, if the code does not throw an exception the transaction is committed, otherwise the transaction will be rolled back. [see](https://laravel.com/docs/10.x/database#database-transactions)

```
wrapper()->transaction();
```

#### *catch()*

[](#catch)

The `catch` method defines how to handle an exception that is thrown.

```
wrapper()->catch(false);
wrapper()->catch(fn() => false);
wrapper()->catch(fn(Throwable $e) => $e);
```

#### *unless()*

[](#unless)

The `unless` method executes the given callback if the given value is falsy, or returns the action's result.

```
wrapper()->unless(fn(mixed $result): mixed => false, fn(): mixed => false);
```

```
wrapper()->unless(false, fn(mixed $result): mixed => $result);
```

#### *unsetModelRelations()*

[](#unsetmodelrelations)

The `unsetModelRelations` method unsets all the loaded relations from the model. [see](https://laravel.com/api/10.x/Illuminate/Database/Eloquent/Concerns/HasRelationships.html#method_unsetRelations)

```
wrapper()->unsetModelRelations();
```

#### *when()*

[](#when)

The `when` method executes the given callable if the given value is truthy, or returns the action's result.

```
wrapper()->when(fn(mixed $result): mixed => true, fn(): mixed => true);
```

```
wrapper()->when(true, fn(mixed $result): mixed => $result);
```

#### *wrap()*

[](#wrap)

The `wrap` method wraps the result in the given class.

```
wrapper()->wrap();
```

Artisan commands
----------------

[](#artisan-commands)

The `make:action` command makes an action class. The command tries to guess the action from the model and uses the template. Also, you don't need to specify the model, use the name 'CreateUser' or 'CreateUserAction' with the option `-m` and watch the magic happen. If the model has a directory (e.g. 'User'), you will use the name 'User/CreateUser' or 'User/CreateUserAction'.

#### make:action

[](#makeaction)

```
php artisan make:action FooAction
```

You can use the option `-d` to create a DTO.

```
php artisan make:action FooAction -d
```

#### make:dto

[](#makedto)

The `make:dto` command makes the dto class.

```
php artisan make:dto FooDto
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [MIT license file](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~80 days

Total

7

Last Release

394d ago

Major Versions

v0.1.0 → v1.0.02024-06-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/f46b04ddacb8fa3070409c06ca40cab92be01fbb8911e3b6d2f00f18733d37b4?d=identicon)[R3bzya](/maintainers/R3bzya)

---

Top Contributors

[![R3bzya](https://avatars.githubusercontent.com/u/61825630?v=4)](https://github.com/R3bzya "R3bzya (57 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/r3bzya-action-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/r3bzya-action-wrapper/health.svg)](https://phpackages.com/packages/r3bzya-action-wrapper)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
