Searching & Filtering
Adding Filters
php
use Rollogi\LaravelHubspot\Crm\Contact;
$contacts = Contact::query()
->where('email', '=', 'john@example.com')
->get();When using =, you can omit the operator:
php
$contacts = Contact::query()
->where('email', 'john@example.com')
->get();Available Operators
| Operator | HubSpot Equivalent | Example |
|---|---|---|
= | EQ | ->where('email', '=', 'john@example.com') |
!= | NEQ | ->where('status', '!=', 'closed') |
< | LT | ->where('amount', '<', 1000) |
<= | LTE | ->where('amount', '<=', 1000) |
> | GT | ->where('amount', '>', 500) |
>= | GTE | ->where('amount', '>=', 500) |
like | CONTAINS_TOKEN | ->where('email', 'like', 'example.com') |
not like | NOT_CONTAINS_TOKEN | ->where('email', 'not like', 'spam.com') |
exists | HAS_PROPERTY | ->where('phone', 'exists') |
not exists | NOT_HAS_PROPERTY | ->where('phone', 'not exists') |
BETWEEN | BETWEEN | ->where('amount', 'BETWEEN', [100, 500]) |
IN | IN | ->where('status', 'IN', ['open', 'pending']) |
Carbon instances are automatically cast to Unix timestamps when used as filter values.
Full-Text Search
php
use Rollogi\LaravelHubspot\Crm\Contact;
$contacts = Contact::query()
->search('John')
->get();Sorting
php
use Rollogi\LaravelHubspot\Crm\Contact;
$contacts = Contact::query()
->orderBy(property: 'createdate', direction: 'DESC')
->get();Chaining Filters (AND)
Multiple where() calls within the same group are combined with AND logic:
php
use Rollogi\LaravelHubspot\Crm\Deal;
$deals = Deal::query()
->where('dealstage', 'closedwon')
->where('amount', '>=', 10000)
->orderBy(property: 'closedate', direction: 'DESC')
->get();OR Filter Groups
Use orWhere() to start a new filter group. Groups are combined with OR logic, while filters within each group use AND logic:
php
use Rollogi\LaravelHubspot\Crm\Contact;
// Find contacts named John OR Jane
$contacts = Contact::query()
->where('firstname', 'John')
->orWhere('firstname', 'Jane')
->get();
// Complex: (firstname=John AND lastname=Doe) OR (firstname=Jane AND lastname=Smith)
$contacts = Contact::query()
->where('firstname', 'John')
->where('lastname', 'Doe')
->orWhere('firstname', 'Jane')
->where('lastname', 'Smith')
->get();Retrieval Methods
php
use Rollogi\LaravelHubspot\Crm\Contact;
// Get a collection of results
$contacts = Contact::query()->where('email', 'like', 'example.com')->get();
// Get just the first result
$contact = Contact::query()->where('email', 'john@example.com')->first();
// Get a count of matching records
$count = Contact::query()->where('email', 'like', 'example.com')->count();