Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ti Ext Automation Laravel Package

tastyigniter/ti-ext-automation

Automate TastyIgniter tasks with scheduled workflows and event-based rules. Trigger actions like order updates, customer notifications, and system maintenance automatically, reducing manual work and improving operational consistency.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the package via Composer:

    composer require tastyigniter/ti-ext-automation
    

    Publish the config file (if needed):

    php artisan vendor:publish --provider="TastyIgniter\TiExtAutomation\TiExtAutomationServiceProvider" --tag="config"
    
  2. Basic Setup Register an automation rule in config/ti-ext-automation.php:

    'rules' => [
        'user_created' => [
            'trigger' => 'user.created',
            'actions' => [
                'send_welcome_email',
                'log_activity',
            ],
        ],
    ],
    

    Define actions in a service provider (e.g., AppServiceProvider):

    public function boot()
    {
        TiExtAutomation::action('send_welcome_email', function ($user) {
            Mail::to($user->email)->send(new WelcomeEmail($user));
        });
    }
    
  3. First Use Case Trigger an automation when a user registers:

    event(new Registered($user)); // Laravel's default event
    // Automatically triggers 'user.created' rule and its actions.
    

Implementation Patterns

Common Workflows

  1. Event-Driven Triggers

    • Use Laravel’s built-in events (e.g., user.created, order.placed) or custom events.
    • Example:
      TiExtAutomation::trigger('user.created', ['user' => $user]);
      
  2. Conditional Actions

    • Filter actions based on data:
      TiExtAutomation::action('notify_admin_if_premium', function ($user) {
          if ($user->isPremium()) {
              Notification::send(new AdminAlert($user));
          }
      });
      
  3. Queueing Actions

    • Offload heavy tasks to queues:
      TiExtAutomation::action('process_payment', function ($order) {
          ProcessPaymentJob::dispatch($order);
      });
      
  4. Dynamic Rule Loading

    • Load rules from a database or API:
      $rules = RuleRepository::fetchDynamicRules();
      TiExtAutomation::loadRules($rules);
      
  5. Integration with Observers

    • Attach automations to model events:
      User::observe(UserAutomationObserver::class);
      
      class UserAutomationObserver {
          public function created(User $user) {
              TiExtAutomation::trigger('user.created', ['user' => $user]);
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Circular Dependencies

    • Avoid actions that trigger the same rule recursively (e.g., send_emaillog_email_sentsend_email).
    • Fix: Use a triggered flag or queue delays.
  2. Missing Dependencies

    • Ensure all actions are registered before triggering rules.
    • Fix: Register actions in a service provider’s boot() method.
  3. Performance Overhead

    • Complex rules with many actions may slow down event handling.
    • Fix: Use queues (dispatch()) for non-critical actions.
  4. Config Overrides

    • Rules in config/ti-ext-automation.php are merged with dynamic rules. Unexpected behavior may occur if keys clash.
    • Fix: Use unique rule names (e.g., user.created.v1).

Debugging Tips

  • Log Triggers: Enable debug logging in the config:

    'debug' => true,
    

    Check storage/logs/laravel.log for triggered actions.

  • Validate Rules: Use Artisan command to validate rules:

    php artisan ti-automation:validate
    
  • Test Incrementally: Start with one rule/action, then expand. Example:

    TiExtAutomation::trigger('test_rule', ['data' => 'test']);
    

Extension Points

  1. Custom Triggers Extend the trigger system by implementing TastyIgniter\TiExtAutomation\Contracts\Triggerable:

    class CustomTrigger implements Triggerable {
        public function trigger(string $rule, array $data) {
            // Custom logic (e.g., API call)
        }
    }
    
  2. Action Middleware Add middleware to actions:

    TiExtAutomation::action('send_email')
        ->middleware(Throttle::class)
        ->execute(function ($user) {
            // ...
        });
    
  3. Rule Validation Add validation to rules using Laravel’s Validator:

    TiExtAutomation::rule('user_created')
        ->validate(function ($data) {
            return Validator::make($data, ['user.email' => 'required|email']);
        });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor