PHPackages                             laraditz/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. laraditz/action

ActiveLaravel-package[Framework](/categories/framework)

laraditz/action
===============

A simple single action class for Laravel to keep your application DRY

2.1.0(1w ago)01.4kMITPHPPHP ^8.2

Since Jun 18Pushed 1w ago1 watchersCompare

[ Source](https://github.com/laraditz/action)[ Packagist](https://packagist.org/packages/laraditz/action)[ Docs](https://github.com/laraditz/action)[ RSS](/packages/laraditz-action/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (7)Used By (0)

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

[](#laravel-action)

[![Latest Stable Version](https://camo.githubusercontent.com/b5d9d8218b65946bc7e1fa4a51ab841e4c70d6bf3a67a6a02246002d2eabdbe2/68747470733a2f2f706f7365722e707567782e6f72672f6c6172616469747a2f616374696f6e2f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/laraditz/action)[![Total Downloads](https://camo.githubusercontent.com/882fecd116e5b463cabdeb63f0c8c687305545dd66ba58e7a30205afb0965ca9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6172616469747a2f616374696f6e3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laraditz/action)[![License](https://camo.githubusercontent.com/c30c7097ac52a50b51e5e7b7e728036d3e16dba85ce444bb0483b32c84a32252/68747470733a2f2f706f7365722e707567782e6f72672f6c6172616469747a2f616374696f6e2f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/laraditz/action)

Single action class for Laravel to keep your application DRY. Each action encapsulates one business operation, receives its input through the constructor, and resolves services automatically via Laravel's container.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 9 – 13

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

[](#installation)

```
composer require laraditz/action
```

Creating an Action
------------------

[](#creating-an-action)

Use the Artisan command to generate an action class (placed in `app/Actions/` by default):

```
php artisan make:action CreateNewPost
```

Fill in the generated file:

```
namespace App\Actions;

use App\Models\Post;
use Laraditz\Action\Action;

class CreateNewPost extends Action
{
    public function __construct(
        public string $title,
        public string $body,
    ) {}

    public function handle(): Post
    {
        return Post::create($this->data());
    }
}
```

Running an Action
-----------------

[](#running-an-action)

**Instance style** — construct first, then call `run()`:

```
$post = (new CreateNewPost(title: 'Hello', body: 'World'))->run();
```

**Static style** — constructor arguments are passed directly to `run()`:

```
$post = CreateNewPost::run(title: 'Hello', body: 'World');
```

Both styles are equivalent.

Dependency Injection
--------------------

[](#dependency-injection)

Type-hint services in `handle()` and Laravel's container injects them automatically:

```
namespace App\Actions;

use App\Mail\PostCreated;
use App\Models\Post;
use Illuminate\Contracts\Mail\Mailer;
use Laraditz\Action\Action;

class PublishPost extends Action
{
    public function __construct(
        public string $title,
        public string $body,
        public string $authorEmail,
    ) {}

    public function handle(Mailer $mailer): Post
    {
        $post = Post::create($this->data());

        $mailer->to($this->authorEmail)->send(new PostCreated($post));

        return $post;
    }
}
```

```
// $mailer is resolved from the container automatically
PublishPost::run(
    title: 'My Post',
    body: 'Content here',
    authorEmail: 'author@example.com',
);
```

Queue Support
-------------

[](#queue-support)

Make an action queueable by implementing `ShouldQueue` and adding the standard Laravel queue traits. Do **not** add `Dispatchable` — the base `Action` class already provides `dispatch()`.

```
namespace App\Actions;

use App\Mail\WelcomeEmail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Laraditz\Action\Action;

class SendWelcomeEmail extends Action implements ShouldQueue
{
    use Queueable, InteractsWithQueue, SerializesModels;

    public function __construct(
        public string $email,
        public string $name,
    ) {}

    public function handle(Mailer $mailer): void
    {
        $mailer->to($this->email)->send(new WelcomeEmail($this->name));
    }
}
```

**Dispatching to the queue:**

```
// Using the base class static dispatch()
SendWelcomeEmail::dispatch(email: 'user@example.com', name: 'Alice');

// Using Laravel's global helper
dispatch(new SendWelcomeEmail(email: 'user@example.com', name: 'Alice'));
```

When the queue worker processes the job, Laravel's `CallQueuedHandler` calls `handle()` through the container, so type-hinted dependencies are injected automatically — the same as when running synchronously.

> **Note:** Do not add `use Illuminate\Foundation\Bus\Dispatchable` to your action class. The base `Action` class already provides `dispatch()`, and adding the trait will cause a conflict.

The `data()` Helper
-------------------

[](#the-data-helper)

`data()` returns all constructor-promoted properties as a key–value array, which is handy for mass-assignment:

```
public function handle(): Post
{
    // Returns ['title' => '...', 'body' => '...']
    return Post::create($this->data());
}
```

Actions with no constructor return an empty array from `data()`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Raditz Farhan](https://github.com/raditzfarhan)

License
-------

[](#license)

MIT. Please see the [license file](LICENSE) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance98

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity73

Established project with proven stability

 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 ~549 days

Total

5

Last Release

9d ago

Major Versions

1.0.2 → 2.0.02025-06-09

PHP version history (3 changes)1.0.0PHP ^7.2.5

2.0.0PHP ^8.0

2.1.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1203676?v=4)[Raditz Farhan](/maintainers/raditzfarhan)[@raditzfarhan](https://github.com/raditzfarhan)

---

Top Contributors

[![raditzfarhan](https://avatars.githubusercontent.com/u/1203676?v=4)](https://github.com/raditzfarhan "raditzfarhan (40 commits)")

---

Tags

laraveldryaction

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.3k](/packages/laravel-sail)[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M631](/packages/spatie-laravel-medialibrary)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M193](/packages/laravel-ai)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.5k21.5M593](/packages/laravel-boost)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)

PHPackages © 2026

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