PHPackages                             stechstudio/laravel-hubspot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. stechstudio/laravel-hubspot

ActiveLibrary[API Development](/categories/api)

stechstudio/laravel-hubspot
===========================

A Laravel SDK for the HubSpot CRM Api

0.19(2mo ago)2971.0k↓14.7%12MITPHPPHP ^8.3CI passing

Since Sep 21Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/stechstudio/laravel-hubspot)[ Packagist](https://packagist.org/packages/stechstudio/laravel-hubspot)[ Docs](https://github.com/stechstudio/laravel-hubspot)[ RSS](/packages/stechstudio-laravel-hubspot/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (21)Used By (0)

HubSpot CRM SDK for Laravel
===========================

[](#hubspot-crm-sdk-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a691971978c16f3e1c10af3413b6d43c653355a0fab1199ec7805110d50301a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737465636873747564696f2f6c61726176656c2d68756273706f742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stechstudio/laravel-hubspot)

Interact with HubSpot's CRM with an enjoyable, Eloquent-like developer experience.

- Familiar Eloquent CRUD methods `create`, `find`, `update`, and `delete`
- Associated objects work like relations: `Deal::find(555)->notes` and `Contact::find(789)->notes()->create(...)`
- Retrieving lists of objects feels like a query builder: `Company::where('state','NC')->orderBy('custom_property')->paginate(20)`
- Cursors provide a seamless way to loop through all records: `foreach(Contact::cursor() AS $contact) { ... }`

> **Note**Only the CRM API is currently implemented.

Installation
------------

[](#installation)

### 1) Install the package via composer:

[](#1-install-the-package-via-composer)

```
composer require stechstudio/laravel-hubspot
```

### 2) Configure HubSpot

[](#2-configure-hubspot)

[Create a private HubSpot app](https://developers.hubspot.com/docs/api/private-apps#create-a-private-app) and give it appropriate scopes for what you want to do with this SDK.

Copy the provided access token, and add to your Laravel `.env` file:

```
HUBSPOT_ACCESS_TOKEN=XXX-XXX-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
```

Usage
-----

[](#usage)

### Individual CRUD actions

[](#individual-crud-actions)

#### Retrieving

[](#retrieving)

You may retrieve single object records using the `find` method on any object class and providing the ID.

```
use STS\HubSpot\Crm\Contact;

$contact = Contact::find(123);
```

#### Creating

[](#creating)

To create a new object record, use the `create` method and provide an array of properties.

```
$contact = Contact::create([
    'firstname' => 'Test',
    'lastname' => 'User',
    'email' => 'testuser@example.com'
]);
```

Alternatively you can create the class first, provide properties one at a time, and then `save`.

```
$contact = new Contact;
$contact->firstname = 'Test';
$contact->lastname = 'User';
$contact->email = 'testuser@example.com';
$contact->save();
```

#### Updating

[](#updating)

Once you have retrieved or created an object, update with the `update` method and provide an array of properties to change.

```
Contact::find(123)->update([
    'email' => 'newemail@example.com'
]);
```

You can also change properties individually and then `save`.

```
$contact = Contact::find(123);
$contact->email = 'newemail@example.com';
$contact->save();
```

#### Deleting

[](#deleting)

This will "archive" the object in HubSpot.

```
Contact::find(123)->delete();
```

### Retrieving multiple objects

[](#retrieving-multiple-objects)

Fetching a collection of objects from an API is different from querying a database directly in that you will always be limited in how many items you can fetch at once. You can't ask HubSpot to return ALL your contacts if you have thousands.

This package provides three different ways of fetching these results.

#### Paginating

[](#paginating)

Similar to a traditional database paginated result, you can paginate through a HubSpot collection of objects. You will receive a `LengthAwarePaginator` just like with Eloquent, which means you can generate links in your UI just like you are used to.

```
$contacts = Contact::paginate(20);
```

By default, this `paginate` method will look at the `page` query parameter. You can customize the query parameter key by passing a string as the second argument.

#### Cursor iteration

[](#cursor-iteration)

You can use the `cursor` method to iterate over the entire collection of objects. This uses [lazy collections](https://laravel.com/docs/9.x/collections#lazy-collections) and [generators](https://www.php.net/manual/en/language.generators.overview.php)to seamlessly fetch chunks of records from the API as needed, hydrating objects when needed, and providing smooth iteration over a limitless number of objects.

```
// This will iterate over ALL your contacts!
foreach(Contact::cursor() AS $contact) {
    echo $contact->id . "";
}
```

> **Warning**API rate limiting can be an obstacle when using this approach. Be careful about iterating over huge datasets very quickly, as this will still require quite a few API calls in the background.

#### Manually fetching chunks

[](#manually-fetching-chunks)

Of course, you can grab collections of records with your own manual pagination or chunking logic. Use the `take` and `after` methods to specify what you want to grab, and then `get`.

```
// This will get 100 contact records, starting at 501
$contacts = Contact::take(100)->after(500)->get();

// This will get the default 50 records, starting at the first one
$contacts = Contact::get();
```

### Searching and filtering

[](#searching-and-filtering)

When retrieving multiple objects, you will frequently want to filter, search, and order these results. You can use a fluent interface to build up a query before retrieving the results.

#### Adding filters

[](#adding-filters)

Use the `where` method to add filters to your query. You can use any of the supported operators for the second argument, see here for the full list: ;

This package also provides friendly aliases for common operators `=`, `!=`, `>`, `>=`, `get();
```

You can omit the operator argument and `=` will be used.

```
Contact::where('email', 'johndoe@example.com')->get();
```

For the `BETWEEN` operator, provide the lower and upper bounds as a two-element tuple.

```
Contact::where('days_to_close', 'BETWEEN', [30, 60])->get();
```

> **Note**All filters added are grouped as "AND" filters, and applied together. Optional "OR" grouping is not yet supported.

#### Searching common properties

[](#searching-common-properties)

HubSpot supports searching through certain object properties very easily. See here for details:

Specify a search parameter with the `search` method:

```
Contact::search('1234')->get();
```

#### Ordering

[](#ordering)

You can order the results with any property.

```
Contact::orderBy('lastname')->get();
```

The default direction is `asc`, you can change this to `desc` if needed.

```
Contact::orderBy('days_to_close', 'desc')->get();
```

### Associations

[](#associations)

HubSpot associations are handled similar to Eloquent relationships.

#### Dynamic properties

[](#dynamic-properties)

You can access associated objects using dynamic properties.

```
foreach(Company::find(555)->contacts AS $contact) {
    echo $contact->email;
}
```

#### Association methods

[](#association-methods)

If you need to add additional constraints, use the association method. You can add any of the filtering, searching, or ordering methods described above.

```
Company::find(555)->contacts()
    ->where('days_to_close', 'BETWEEN', [30, 60])
    ->search('smith')
    ->get();
```

#### Eager loading association IDs

[](#eager-loading-association-ids)

Normally, there are three HubSpot API calls to achieve the above result:

1. Fetch the company object
2. Retrieve all the contact IDs that are associated to this company
3. Query for contacts that match the IDs

Now we can eliminate the second API call by eager loading the associated contact IDs. This library always eager-loads the IDs for associated companies, contacts, deals, and tickets. It does not eager-load IDs for engagements like emails and notes, since those association will tend to be much longer lists.

If you know in advance that you want to, say, retrieve the notes for a contact, you can specify this up front.

```
// This will only be two API calls, not three
Contact::with('notes')->find(123)->notes;
```

#### Creating associated objects

[](#creating-associated-objects)

You can create new records off of the association methods.

```
Company::find(555)->contacts()->create([
    'firstname' => 'Test',
    'lastname' => 'User',
    'email' => 'testuser@example.com'
]);
```

This will create a new contact, associate it to the company, and return the new contact.

You can also associate existing objects using `attach`. This method accepts and ID or an object instance.

```
Company::find(555)->contacts()->attach(Contact::find(123));
```

You can also detach existing objects using `detach`. This method accepts and ID or an object instance.

```
Company::find(555)->contacts()->detach(Contact::find(123));
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance87

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~67 days

Total

20

Last Release

62d ago

PHP version history (3 changes)0.1PHP ^8.1

0.18PHP ^8.2

0.19PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/315be5f111b5501a41b99a0205c9c85915335391168a0ed10316546a1a38bbd8?d=identicon)[jszobody](/maintainers/jszobody)

---

Top Contributors

[![jszobody](https://avatars.githubusercontent.com/u/203749?v=4)](https://github.com/jszobody "jszobody (47 commits)")[![BinaryKitten](https://avatars.githubusercontent.com/u/67553?v=4)](https://github.com/BinaryKitten "BinaryKitten (44 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (8 commits)")[![shawnhooper](https://avatars.githubusercontent.com/u/2073284?v=4)](https://github.com/shawnhooper "shawnhooper (8 commits)")[![rjm87](https://avatars.githubusercontent.com/u/57094396?v=4)](https://github.com/rjm87 "rjm87 (5 commits)")[![AdamRollinson](https://avatars.githubusercontent.com/u/15811348?v=4)](https://github.com/AdamRollinson "AdamRollinson (3 commits)")[![imoceanic](https://avatars.githubusercontent.com/u/2804551?v=4)](https://github.com/imoceanic "imoceanic (3 commits)")[![leolll](https://avatars.githubusercontent.com/u/2875387?v=4)](https://github.com/leolll "leolll (2 commits)")[![mapo-89](https://avatars.githubusercontent.com/u/118180259?v=4)](https://github.com/mapo-89 "mapo-89 (2 commits)")[![julien-libert](https://avatars.githubusercontent.com/u/100412687?v=4)](https://github.com/julien-libert "julien-libert (2 commits)")[![mterchila](https://avatars.githubusercontent.com/u/11842429?v=4)](https://github.com/mterchila "mterchila (1 commits)")[![emaadali](https://avatars.githubusercontent.com/u/3521616?v=4)](https://github.com/emaadali "emaadali (1 commits)")

---

Tags

laravelhubspotstechstudio

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/stechstudio-laravel-hubspot/health.svg)

```
[![Health](https://phpackages.com/badges/stechstudio-laravel-hubspot/health.svg)](https://phpackages.com/packages/stechstudio-laravel-hubspot)
```

###  Alternatives

[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[combindma/laravel-facebook-pixel

Meta pixel integration for Laravel

4956.9k](/packages/combindma-laravel-facebook-pixel)[njoguamos/laravel-plausible

A laravel package for interacting with plausible analytics api.

208.8k](/packages/njoguamos-laravel-plausible)[tapp/filament-webhook-client

Add a Filament resource and a policy for Spatie Webhook client

1120.2k](/packages/tapp-filament-webhook-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
