PHP code example of tapp / laravel-hubspot

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

    

tapp / laravel-hubspot example snippets


// config/hubspot.php
'contact_email_properties' => [
    'email',
    'secondary_email',
    'work_email',
    'personal_email',
],

use Tapp\LaravelHubspot\Models\HubspotContact;
use Tapp\LaravelHubspot\Contracts\HubspotModelInterface;

class User extends Authenticatable implements HubspotModelInterface
{
    use HubspotContact;

    public array $hubspotMap = [
        'email' => 'email',
        'first_name' => 'first_name',
        'last_name' => 'last_name',
        'user_type' => 'type.name', // Supports dot notation for relations
        'app_last_login' => 'last_login',
    ];

    // Stay in `$hubspotMap` so they still sync with other changes / bulk sync,
    // but do not queue a job when they are the only dirty attributes.
    public array $hubspotSyncIgnoredFields = [
        'last_login',
    ];
}

use Tapp\LaravelHubspot\Models\HubspotCompany;
use Tapp\LaravelHubspot\Contracts\HubspotModelInterface;

class Company extends Model implements HubspotModelInterface
{
    use HubspotCompany;

    public array $hubspotMap = [
        'name' => 'name',
        'domain' => 'domain',
        'industry' => 'industry',
    ];
}

class User extends Authenticatable implements HubspotModelInterface
{
    use HubspotContact;

    public function getHubspotProperties(array $map): array
    {
        return [
            'full_name' => $this->first_name . ' ' . $this->last_name,
            'display_name' => $this->getDisplayName(),
            'account_age_days' => $this->created_at->diffInDays(now()),
        ];
    }
}

use App\Models\User;
use App\Models\Company;
use Tapp\LaravelHubspot\Observers\HubspotContactObserver;
use Tapp\LaravelHubspot\Observers\HubspotCompanyObserver;

public function boot(): void
{
    User::observe(HubspotContactObserver::class);
    Company::observe(HubspotCompanyObserver::class);
}
bash
composer vendor:publish --tag="laravel-hubspot-config"
php artisan vendor:publish --tag="hubspot-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="laravel-hubspot-config"
bash
php artisan hubspot:sync-properties
bash
php artisan queue:work --queue=hubspot
bash
export HUBSPOT_TEST_API_KEY=your_test_api_key_here
php artisan hubspot:sync-properties