PHPackages                             panchodp/laravel-actions - 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. panchodp/laravel-actions

ActiveLibrary

panchodp/laravel-actions
========================

Make your Laravel actions classes fast and in a simple way.

v2.4.2(1mo ago)3225↓100%MITPHPPHP ^8.3CI passing

Since Jul 6Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/PanchoDP/laravel-actions)[ Packagist](https://packagist.org/packages/panchodp/laravel-actions)[ RSS](/packages/panchodp-laravel-actions/feed)WikiDiscussions master Synced 1mo ago

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

 [![Logo for Laravel Action](art/laravel-action.webp)](art/laravel-action.webp)

[![Php](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)[![Total Downloads](https://camo.githubusercontent.com/d35af18867454950d9cee8434cc911397bb5b99897fcdf7cc79f6d7ee9b71d0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616e63686f64702f6c61726176656c2d616374696f6e733f)](https://camo.githubusercontent.com/d35af18867454950d9cee8434cc911397bb5b99897fcdf7cc79f6d7ee9b71d0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616e63686f64702f6c61726176656c2d616374696f6e733f)[![Latest Stable Version](https://camo.githubusercontent.com/8347dffbad3d831b4c7779ccbd2eb3cb1b34da498ea056fb70f006d4ae368707/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616e63686f64702f6c61726176656c2d616374696f6e732e7376673f)](https://packagist.org/packages/panchodp/laravel-actions)[![License](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](https://packagist.org/packages/panchodp/laravel-actions)[![Tests](https://github.com/PanchoDP/laravel-actions/actions/workflows/tests.yml/badge.svg)](https://github.com/PanchoDP/laravel-actions/actions/workflows/tests.yml)

Laravel Actions
===============

[](#laravel-actions)

Make your Laravel actions classes fast and in a simple way.

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

[](#installation)

You can install the package via composer:

```
composer require panchodp/laravel-actions --dev
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Panchodp\LaravelAction\LaravelActionServiceProvider" --tag="laravel-actions-config"
```

This creates `config/laravel-actions.php`:

```
return [
    'base_folder' => 'Actions',
    'method_name' => 'handle',
];
```

- `base_folder`: Base folder where action classes are created. Defaults to `Actions` (`app/Actions`).
- `method_name`: Method name generated in action classes. Defaults to `handle`.

Customizing Stubs
-----------------

[](#customizing-stubs)

You can publish and edit the stub templates used to generate action classes:

```
php artisan vendor:publish --provider="Panchodp\LaravelAction\LaravelActionServiceProvider" --tag="laravel-actions-stubs"
```

This publishes the 4 stubs to `resources/stubs/vendor/laravel-actions/`. Once published, the package will use your custom stubs instead of the defaults. You can customize each stub independently — any stub not found in your published directory will fall back to the package default.

Method Types
------------

[](#method-types)

By default, Laravel Actions generates **instance methods** for better flexibility and dependency injection support. However, you can create **static methods** when needed for simpler usage.

### Instance Methods (Default)

[](#instance-methods-default)

```
// Usage
$action = new MyAction();
$action->handle($attributes);

// Generated code
public function handle(array $attributes): void
{
    // Implementation
}
```

### Static Methods

[](#static-methods)

```
// Usage
MyAction::handle($attributes);

// Generated code
public static function handle(array $attributes): void
{
    // Implementation
}
```

Usage
-----

[](#usage)

### Interactive Mode

[](#interactive-mode)

Run `make:action` without arguments to launch an interactive wizard:

```
php artisan make:action
```

```
 ┌ Action name ───────────────────────────────────────────────┐
 │ e.g. CreateUser                                            │
 └────────────────────────────────────────────────────────────┘
 ┌ Subfolder (optional) ──────────────────────────────────────┐
 │ e.g. User or User/Auth                                     │
 └────────────────────────────────────────────────────────────┘
 ┌ Include DB transaction? ───────────────────────────────────┐
 │ ● Yes / ○ No                                               │
 └────────────────────────────────────────────────────────────┘
 ...

```

### Creating Actions

[](#creating-actions)

To create an action class, use the `make:action` command. You can specify the full path using forward slashes `/` or backslashes `\` (Laravel-style syntax):

**Basic action:**

```
php artisan make:action MyAction
```

This creates a new action class in the `app/Actions` directory.

**Action in a subfolder:**

```
php artisan make:action User/CreateAccount
```

This creates the action in `app/Actions/User/CreateAccount.php`.

**Action in nested subfolders:**

```
php artisan make:action User/Auth/Login
```

This creates the action in `app/Actions/User/Auth/Login.php`.

**Using backslashes (alternative syntax):**

```
php artisan make:action Admin\DeletePost
```

This creates the action in `app/Actions/Admin/DeletePost.php`.

The generated class will have a `handle` method where you can implement your action logic:

```
