lorisleiva/laravel-actions

Laravel components that take care of one specific task
10,893,562 2,872
Install
composer require lorisleiva/laravel-actions
Latest Version:2.13.0
PHP:^8.2
Laravel:11 · 12 · 13
Older releases:5 – 10
License:MIT
Last Updated:Oct 15, 2026
Links: GitHub  ·  Packagist
Maintainer: lorisleiva

⚡️ Laravel Actions

Latest Version on Packagist GitHub Tests Action Status Total Downloads

hero

⚡ Classes that take care of one specific task.

This package introduces a new way of organising the logic of your Laravel applications by focusing on the actions your applications provide.

Instead of creating controllers, jobs, listeners and so on, it allows you to create a PHP class that handles a specific task and run that class as anything you want.

Therefore it encourages you to switch your focus from:

"What controllers do I need?", "should I make a FormRequest for this?", "should this run asynchronously in a job instead?", etc.

to:

"What does my application actually do?"

Installation

composer require lorisleiva/laravel-actions

Documentation

:books: Read the full documentation at laravelactions.com

Basic usage

Create your first action using php artisan make:action PublishANewArticle and define the asX methods when you want your action to be running as X. E.g. asController, asJob, asListener and/or asCommand.

class PublishANewArticle
{
    use AsAction;

    public function handle(User $author, string $title, string $body): Article
    {
        return $author->articles()->create([
            'title' => $title,
            'body' => $body,
        ]);
    }

    public function asController(Request $request): ArticleResource
    {
        $article = $this->handle(
            $request->user(),
            $request->get('title'),
            $request->get('body'),
        );

        return new ArticleResource($article);
    }

    public function asListener(NewProductReleased $event): void
    {
        $this->handle(
            $event->product->manager,
            $event->product->name . ' Released!',
            $event->product->description,
        );
    }
}

As an object

Now, you can run your action as an object by using the run method like so:

PublishANewArticle::run($author, 'My title', 'My content');

As a controller

Simply register your action as an invokable controller in a routes file.

Route::post('articles', PublishANewArticle::class)->middleware('auth');

As a listener

Simply register your action as a listener of the NewProductReleased event.

Event::listen(NewProductReleased::class, PublishANewArticle::class);

Then, the asListener method of your action will be called whenever the NewProductReleased event is dispatched.

event(new NewProductReleased($manager, 'Product title', 'Product description'));

And more...

On top of running your actions as objects, controllers and listeners, Laravel Actions also supports jobs, commands and even mocking your actions in tests.

📚 Check out the full documentation to learn everything that Laravel Actions has to offer.

Related Packages

syamsoul/laravel-action-delay

Delay a Job, Database Query or PHP code at a specific datetime easily with one s...

171 1
mxl/laravel-job

Laravel job tools

1,659,888 66
haykel/laravel-action-maker

A Laravel package to generate Action classes with optional DB transactions and P...

1 0
scrumble-nl/laravel-csr

This package makes it possible to generate a controller, service, repository, mo...

23,081 42
madnh/laravel-command-util

Utils for a laravel command class

146 1

Version History

Version Released PHP Laravel License
2.13.0 ^8.2 ^11.0|^12.0|^13.0 MIT
v2.12.0 ^8.2 ^11.0|^12.0|^13.0 MIT
v2.11.0 ^8.2 ^11.0|^12.0|^13.0 MIT
v2.10.2 ^8.2 ^11.0|^12.0|^13.0 MIT
v2.10.1 ^8.2 ^11.0|^12.0|^13.0 MIT
Pre-releases (2)
Version Released PHP Laravel License
v2.3.0-beta.2 ^8.0 ^8.15|^9.0 MIT
v2.3.0-beta ^8.0 ^8.15|9.x-dev MIT