tschope / laravel-hubspot
为 Hubspot 客户端包添加 Laravel 特定的包装器
v3.0.1
2020-09-16 12:01 UTC
Requires
- illuminate/support: >=5.3
- tschope/hubspot-php: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- orchestra/testbench: >=3.4
This package is auto-updated.
Last update: 2024-09-16 20:46:58 UTC
README
这是一个对 hubspot/hubspot-php 包的包装器,并为用户提供了一个 Service Container 绑定和 facade,用于 SevenShores\Hubspot\Factory::create('api-key')
函数。
安装
composer require rossjcooper/laravel-hubspot
- 从您的 HubSpot 账户的“集成”页面获取 HubSpot API 密钥。
- Laravel 5.4 或更早版本,在您的
config/app.php
文件中- 将
Rossjcooper\LaravelHubSpot\HubSpotServiceProvider::class
添加到您的 providers 数组中。 - 将
'HubSpot' => Rossjcooper\LaravelHubSpot\Facades\HubSpot::class
添加到您的 aliases 数组中。
- 将
- 运行
php artisan vendor:publish --provider="Rossjcooper\LaravelHubSpot\HubSpotServiceProvider" --tag="config"
将创建一个config/hubspot.php
文件。 - 将您的 HubSpot API 密钥添加到您的
.env
文件中:HUBSPOT_API_KEY=yourApiKey
用法
您可以使用 facade 或将 HubSpot 类注入为依赖项
Facade
// Echo all contacts first and last names $response = HubSpot::contacts()->all(); foreach ($response->contacts as $contact) { echo sprintf( "Contact name is %s %s." . PHP_EOL, $contact->properties->firstname->value, $contact->properties->lastname->value ); }
依赖注入
Route::get('/', function (Rossjcooper\LaravelHubSpot\HubSpot $hubspot) { $response = $hubspot->contacts()->all(); foreach ($response->contacts as $contact) { echo sprintf( "Contact name is %s %s." . PHP_EOL, $contact->properties->firstname->value, $contact->properties->lastname->value ); } });
有关使用实际 API 的更多信息,请参阅主仓库 hubspot/hubspot-php
测试
我们使用出色的 Orchestra Testbench v4 在 Laravel 环境中运行单元测试。如果您想运行测试,请确保在您的 .env
文件中有一个 HubSpot API 密钥,并运行 ./vendor/bin/phpunit
当前的单元测试访问 HubSpot API,并期望看到 HubSpot 为其开发者账户提供的演示联系人/潜在客户。
问题
请在此处仅报告与 Laravel 方面相关的问题,主要 API 问题应在此处报告 here