mortenscheel/laravel-automation is a Laravel package for laravel automation framework.
It currently has 1 GitHub stars and 4 downloads on Packagist (latest version v0.1).
Install it with composer require mortenscheel/laravel-automation.
Discover more Laravel packages by mortenscheel
or browse all Laravel packages to compare alternatives.
Last updated
Allow users to configure dynamic automation flows in your Laravel app. Inspired by If this then that, you define a number of triggers and actions, and then allow your users to combine and configure them.
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');
}
AutomationTrigger classesCustom classes that are responsible for discovering models that meet their criteria.
AutomationAction classesCustom Job classes that perform an action on a model.
Automation modelA concrete automation workflow that combines an AutomationTrigger with an AutomationAction.
Also includes (optional) parameters for both the trigger and the action.
AutomationLog modelA record that is created when an Automation is performed on a specific model.
Automatable interfaceIn order to make your models automatable, they must implement the Automatable interface.
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', '<=', now()->subSeconds($this->params->get('age')))
->whereDoesntHave('automationLogs', fn ($logs) => $logs->where('automation_id', $automation->id))
->get();
}
}
The action class is also rather simple:
class SendMailableAction extends \Scheel\Automation\AutomationAction
{
protected function executeAction(): bool
{
$params = $this->log->automation->action_params;
$mailable_class = $params->get('mailable');
$recipient = $this->log->automatable;
$mailable_params = [];
foreach ($params->get('mailable_params', []) as $mailable_param) {
$mailable_params[] = data_get($recipient, $mailable_param);
}
$mailable = new $mailable_class(...$mailable_params);
\Mail::to($recipient)->send($mailable);
return true;
}
}
This package is a work in progress, and feedback or pull requests will be appreciated. These are some of the areas that I would like to improve:
Automation child class (wip).composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.