vertaalbureau-perfect/action-pattern

Action for small code bits, usable in laravel
1,259
Install
composer require vertaalbureau-perfect/action-pattern
Latest Version:v0.2.5
PHP:>=7.4|^8.0|^8.1
Laravel:8 · 9 · 10
License:MIT
Last Updated:Nov 6, 2023
Links: GitHub  ·  Packagist
Maintainer: vertaalbureauperfect

Action Pattern

Actions are meant to be very small, single purpose, bits of code.

Because of the small footprint actions are easy reusable.

Example use cases are:

  • implementing third paty api calls
  • Simple routine jobs

Installation

composer require vertaalbureau-perfect/action-pattern

Creating an Action

php artisan make:action [ActionName]

You can also create actions in sub namespaces:

php artisan make:action [SubNamespace]/[ActionName]

Actions are placed in your app/Actions folder.

Usage

Imagine a simple action to write something to the log:

class CreateLogAction extends AbstractAction
{
    public function handle($message)
    {
        Log::debug($message);
    }
}

And to use it we would simply call:

CreateLogAction::execute('Write me to the log please!');

Testing

For Testing purposes you can use the static fake method.

CreateLogAction::fake();

If your code depends on a return value from the action you can provide the return value in the fake method.

CreateLogAction::fake('Log Success');

Related Packages

millat/laravel-hooks

The WordPress filter, action system in Laravel

38,898 57
tormjens/eventy

The WordPress filter/action system in Laravel

1,011,166 438
grohiro/laravel-action-submit

Laravel ActionSubmit button

42 3
maatwebsite/laravel-nova-excel

Supercharged Excel exports for Laravel Nova Resources

7,184,779 401

Version History

Version Released PHP Laravel License
v0.2.5 >=7.4|^8.0|^8.1 ^8.0|^9.0|^v10.26.2 MIT
v0.2.4 >=7.4|^8.0|^8.1 ^8.0|9.*|^10.0 MIT
v0.2.3 >=7.4|8.0 ^8.0|9.* MIT
v0.2.2 >=7.4|8.0 ^8.0|9.* MIT
v0.2.1 >=7.4|8.0 ^8.0|9.* MIT