Skip to content

CRUD Operations

Finding Records

php
use Rollogi\LaravelHubspot\Crm\Contact;

// Find by ID (returns null if not found)
$contact = Contact::find('123');

// Find or throw NotFoundException
$contact = Contact::findOrFail('123');

// Find or return a new unsaved instance
$contact = Contact::findOrNew('123');

// Find or execute a callback
$contact = Contact::findOr('123', fn (): Contact => Contact::create(['email' => 'fallback@example.com']));

// Find by alternative ID property (e.g. email)
$contact = Contact::find(id: 'john@example.com', idProperty: 'email');

// Find multiple records
$contacts = Contact::find(['123', '456', '789']);

Creating Records

php
use Rollogi\LaravelHubspot\Crm\Contact;

$contact = Contact::create([
    'firstname' => 'Jane',
    'lastname' => 'Smith',
    'email' => 'jane@example.com',
]);

Updating Records

php
// Update with an array
$contact->update(['lastname' => 'Doe']);

// Or set properties and save (uses dirty tracking to only send changes)
$contact->lastname = 'Doe';
$contact->save();

Deleting Records

php
$contact->delete();

Hydrating from API Payloads

If you already have a raw API response array, you can hydrate a model directly:

php
use Rollogi\LaravelHubspot\Crm\Contact;

$contact = Contact::hydrate($apiResponse);