webcartell/anvil

Anvil Container for Apiato.

1.0.0 2025-01-21 20:16 UTC

This package is auto-updated.

Last update: 2025-04-21 20:49:33 UTC


README

Latest Version on Packagist Total Downloads License

A powerful toolkit for Apiato that provides advanced email templating, webhook management, and standardized API patterns.

Features

  • 📧 Dynamic Email Template System
  • 🔗 Webhook Management
  • 🎯 Standardized API Controllers
  • 🛠️ Base Task Implementations
  • 🔄 Event Dispatching
  • 🚀 RPC Action Support

Installation

php composer require webcartell/anvil

Database Setup

Run the migrations to create the necessary tables:

php artisan migrate

This will create:

  • email_templates table for managing email templates
  • webhooks table for webhook configurations

Core Components

1. Email System

The email system provides a flexible templating solution with:

  • Dynamic variable replacement
  • Template caching
  • Active/inactive template states
  • Customizable settings
use App\Containers\Vendor\Anvil\Parents\Mail;

class WelcomeEmail extends Mail
{
    protected string $templateName = 'welcome_email';

    public function variables(): array
    {
        return [
            'user' => [
            'name' => 'John Doe'
            ]
        ];
    }

2. Webhook Management

Easily manage and trigger webhooks for your API events:

use App\Containers\Vendor\Anvil\Models\Webhook;

// Register a webhook
Webhook::create([
    'event' => 'user.created',
    'url' => 'https://your-endpoint.com/webhook',
    'secret_key' => 'your-secret'
]);

3. AnvilController

A powerful base controller that provides:

  • Automatic REST action handling
  • Event dispatching
  • Webhook triggering
  • Transformer integration
use App\Containers\Vendor\Anvil\Parents\AnvilController;

class UserController extends AnvilController
{
    public bool $dispatchesEvent = true;
    public bool $triggersWebhooks = true;
}

4. AnvilTask

Base task implementation with common database operations:

  • Fetch all records
  • Find by ID
  • Create
  • Update
  • Delete

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The MIT License (MIT). Please see License File for more information.

Built for Apiato with ❤️