PHPackages                             iak/action - 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. [Framework](/categories/framework)
4. /
5. iak/action

ActiveLibrary[Framework](/categories/framework)

iak/action
==========

Simple actions for Laravel

2.0.0(1mo ago)80MITPHPPHP ^8.2CI passing

Since Sep 4Pushed 3w agoCompare

[ Source](https://github.com/iaK/action)[ Packagist](https://packagist.org/packages/iak/action)[ Docs](https://github.com/iaK/action)[ GitHub Sponsors]()[ RSS](/packages/iak-action/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (5)Dependencies (33)Versions (27)Used By (0)

Laravel Action
==============

[](#laravel-action)

[![Latest Version on Packagist](https://camo.githubusercontent.com/59c555d820f824079bd623c6da622ac5fa4465fe117f70e3cd37f981376b0fdf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69616b2f616374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iak/action)[![GitHub Tests Action Status](https://camo.githubusercontent.com/831c6e3893f930bf9896adcfb3a332bdb553be1eb78be9a3bbd8e77fe51ad859/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69614b2f616374696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/iaK/action/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/dec180d0a7dae346e97506ea7f78fe2080a5985f9f2f70b44262cd41161e0a22/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69614b2f616374696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/iaK/action/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/263d69ed43d8801314a1c82e327f896a6f05bda3544118ca703b0bf4b12d8640/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69616b2f616374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iak/action)

A dont-get-in-my-way action pattern wrapper for laravel applications.

For a guide on how I use actions, which is also the way this package is tailored towards, see this blogpost:

Why do i need this package?
---------------------------

[](#why-do-i-need-this-package)

The action pattern is awesome because it's dead simple. What this package aims to do, is to provide some helpers and save you from writing the boring boilerplate code, and focus on your business logic.

Stuff like idempotency, concurrency control, database transactions, circuit breaking, retires and debugging is ready to use without it cluttering your code, easy for both humans and agents to reach for.

Lets say you have a piece of code like this:

```
class ChargeOrderAction
{
    public function handle(Order $order): Payment
    {
        $payment = app(PaymentGateway::class)->charge($order->customer, $order->total);

        $order->update(['status' => OrderStatus::Paid]);
        $order->payments()->create([
            'amount' => $order->total,
            'reference' => $payment->reference,
        ]);

        return $payment;
    }
}
```

In reality, you probably won't get away with a solution as simple as this. You will probably need transactions, maybe idempotency, and want to retry it on deadlocks or failures.

Instead of cluttering our beatiful and simple action with that logic, we can instead chain it on when we call it.

```
$payment = ChargeOrderAction::make()
    ->idempotent("order:{$order->id}:charge", ttl: now()->addDay())
    ->retry(times: 3, backoff: [100, 1000])
    ->transactional(attempts: 2)
    ->handle($order);
```

This is just as big a win for agents as it is for you. Instead of generating fifty lines of locking, caching and retry boilerplate — which you then get to review for subtle bugs — an agent chains a few calls that are hard to get wrong and, thanks to the fixed nesting order, impossible to compose incorrectly. The call site ends up documenting its own guarantees, so human and agent alike can tell at a glance what a call does in production. And when something misbehaves, the [debug helpers](#debugging) print straight to stdout — exactly where an agent is already looking.

This wrapper also has the support for eventing and inline actions. More on that below.

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

[](#installation)

```
composer require iak/action
```

The basics
----------

[](#the-basics)

### Creating an action

[](#creating-an-action)

An action is a plain class that extends `Action` and implements a `handle()` method. That's the whole contract — no interfaces, no registration:

```
