PHP code example of elvesora / enrichment-laravel

1. Go to this page and download the library: Download elvesora/enrichment-laravel 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/ */

    

elvesora / enrichment-laravel example snippets




namespace App\Services;

use Elvesora\Enrichment\Laravel\Contracts\EnrichmentClientInterface;
use Elvesora\Enrichment\Laravel\EnrichmentResult;

final class EnrichAccount
{
    public function __construct(
        private readonly EnrichmentClientInterface $enrichment,
    ) {
    }

    public function handle(string $domain, string $jobId): EnrichmentResult
    {
        return $this->enrichment->enrich(
            domain: $domain,
            idempotencyKey: $jobId,
        );
    }
}

use Elvesora\Enrichment\Laravel\Facades\Enrichment;

$result = Enrichment::enrich(
    domain: 'acme.com',
    idempotencyKey: 'crm-account-123',
);

echo $result->data['company_name'] ?? $result->domain;
echo $result->credits->remaining;

use Elvesora\Enrichment\Laravel\Exception\EnrichmentException;
use Elvesora\Enrichment\Laravel\Facades\Enrichment;

try {
    $result = Enrichment::enrich('acme.com', 'crm-account-123');
} catch (\InvalidArgumentException $exception) {
    // Invalid client configuration, domain, or idempotency key.
} catch (\LogicException $exception) {
    // ELVESORA_ENRICHMENT_API_KEY or another package setting is missing.
} catch (EnrichmentException $exception) {
    report($exception);

    if ($exception->retryable) {
        $retryAfter = $exception->retryAfter;
    }
}

$this->app->instance(
    \Elvesora\Enrichment\Laravel\Contracts\EnrichmentClientInterface::class,
    $fakeEnrichmentClient,
);
console
php artisan vendor:publish --tag=enrichment-config