PHPackages                             mortenscheel/laravel-automation - 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. mortenscheel/laravel-automation

ActiveLibrary[Framework](/categories/framework)

mortenscheel/laravel-automation
===============================

Laravel automation framework

v0.1(4y ago)14[2 PRs](https://github.com/mortenscheel/laravel-automation/pulls)MITPHPPHP ^8.0

Since Mar 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mortenscheel/laravel-automation)[ Packagist](https://packagist.org/packages/mortenscheel/laravel-automation)[ Docs](https://github.com/scheel/laravel-automation)[ GitHub Sponsors](https://github.com/mortenscheel)[ RSS](/packages/mortenscheel-laravel-automation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

Laravel Automation
==================

[](#laravel-automation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a0d5ccad7b9535fd72dc53d5fdbfe3f475ce79158ba49a8e7942c826155a6a30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f7274656e73636865656c2f6c61726176656c2d6175746f6d6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mortenscheel/laravel-automation)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b13ec668173c38edca31252420289a5add08f8583cf6d7b054554d7bcd824341/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6f7274656e73636865656c2f6c61726176656c2d6175746f6d6174696f6e2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/mortenscheel/laravel-automation/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f53e60b784df650f9ad1611eb02ecbe95443294f2d22029c29202a39f8f777a4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6f7274656e73636865656c2f6c61726176656c2d6175746f6d6174696f6e2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/scheel/laravel-automation/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/5e89dc98bedec93116a2bf03040d0836d5f8ead61578378b5b23ef73f2042ec3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f7274656e73636865656c2f6c61726176656c2d6175746f6d6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mortenscheel/laravel-automation)

Allow users to configure dynamic automation flows in your Laravel app. Inspired by [If this then that](https://ifttt.com/), you define a number of triggers and actions, and then allow your users to combine and configure them.

Quick start
-----------

[](#quick-start)

Install the package with composer:

```
composer require mortenscheel/laravel-automation
```

Publish and run the migrations:

```
php artisan vendor:publish --tag="automation-migrations"
php artisan migrate
```

Run automations automatically via Laravel's scheduler in `app/Console/Kernel.php`

```
protected function schedule(Schedule $schedule)
{
    // ...
    $schedule->command('automation:run');
}
```

Concepts
--------

[](#concepts)

### `AutomationTrigger` classes

[](#automationtrigger-classes)

Custom classes that are responsible for discovering models that meet their criteria.

### `AutomationAction` classes

[](#automationaction-classes)

Custom Job classes that perform an action on a model.

### `Automation` model

[](#automation-model)

A concrete automation workflow that combines an `AutomationTrigger` with an `AutomationAction`. Also includes (optional) parameters for both the trigger and the action.

### `AutomationLog` model

[](#automationlog-model)

A record that is created when an `Automation` is performed on a specific model.

### `Automatable` interface

[](#automatable-interface)

In order to make your models automatable, they must implement the `Automatable` interface.

Examples
--------

[](#examples)

### Send a welcome email 15 minutes after a new user is created

[](#send-a-welcome-email-15-minutes-after-a-new-user-is-created)

The `Automation` model might look something like this

```
Automation::create([
    'trigger_class' => ModelAgeTrigger::class,
    'trigger_params' => [
        'model' => User::class,
        'age' => 60 * 15,
    ],
    'action_class' => SendMailableAction::class,
    'action_params' => [
        'mailable' => WelcomeEmail::class,
        'mailable_params' => [
            'name',
        ],
    ],
]);
```

The trigger class only need to implement a single method:

```
class ModelAgeTrigger extends \Scheel\Automation\AutomationTrigger
{
    public function discoverAutomatable(Automation $automation): Collection
    {
        $class = $this->params->get('model');
        return $class::query()->where('created_at', '
