PHP code example of esign / laravel-unleash-webhook-client

1. Go to this page and download the library: Download esign/laravel-unleash-webhook-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esign / laravel-unleash-webhook-client example snippets


namespace App\Jobs;

use App\Models\Redirect;
use App\Models\Translation;
use Esign\UnleashWebhookClient\Jobs\ProcessUnleashWebhookJob as BaseProcessUnleashWebhookJob;

class ProcessUnleashWebhookJob extends BaseProcessUnleashWebhookJob
{
    public function handle(): void
    {
        foreach ($this->getWebhookEntries() as $webhookEntry) {
            match ($webhookEntry->table) {
                (new Translation)->getTable() => $this->handleTranslationsWebhook($webhookEntry),
                (new Redirect)->getTable() => $this->handleRedirectsWebhook($webhookEntry),
                default => null,
            };
        }
    }

    protected function handleTranslationsWebhook(WebhookEntry $webhookEntry): void
    {
        // Handle the translation webhook entry
    }

    protected function handleRedirectsWebhook(WebhookEntry $webhookEntry): void
    {
        // Handle the redirects webhook entry
    }
}

use Esign\UnleashWebhookClient\Testing\MocksUnleashWebhooks;

class ExampleTest extends TestCase
{
    use MocksUnleashWebhooks;

    #[Test]
    public function it_can_process_unleash_webhooks(): void
    {
        $responseA = $this->makeUnleashWebhookRequest(['example' => 'data']);
        $responseB = $this->makeUnleashWebhookRequestFromFixture('example-webhook.json');

        $responseA->assertOk();
        $responseB->assertOk();
    }
}