1. Go to this page and download the library: Download asciisd/zoho-v8 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/ */
use Asciisd\Zoho\Facades\Zoho;
// Create a contact
$contact = Zoho::contacts()->create([...]);
// Create a lead
$lead = Zoho::leads()->create([...]);
// Create a deal
$deal = Zoho::deals()->create([...]);
$fields = ZohoContact::getFieldMetadata();
// Each field contains information like:
// - api_name
// - field_label
// - data_type
// - read_only
// -
// Fetch only specific fields
$contact = ZohoContact::find('123', [
'fields' => 'id,First_Name,Last_Name,Email'
]);
// Search with specific fields
$contacts = ZohoContact::all([
'fields' => 'Full_Name,Email,Phone',
'per_page' => 50,
]);
// Clear cache for specific module
ZohoContact::clearFieldCache();
// Clear cache for all modules
ZohoContact::clearAllFieldCache();
use Asciisd\Zoho\Events\ZohoRecordCreated;
use Asciisd\Zoho\Events\ZohoRecordUpdated;
use Asciisd\Zoho\Events\ZohoRecordDeleted;
use Asciisd\Zoho\Events\ZohoWebhookReceived;
// Listen to all webhooks
Event::listen(ZohoWebhookReceived::class, function ($event) {
$module = $event->module;
$eventType = $event->event;
$data = $event->getData();
// Handle webhook
});
// Listen to specific events
Event::listen(ZohoRecordCreated::class, function ($event) {
$module = $event->module; // e.g., 'Contacts'
$record = $event->getData();
$recordId = $event->getRecordId();
// Handle record creation
});
Event::listen(ZohoRecordUpdated::class, function ($event) {
// Handle record update
});
Event::listen(ZohoRecordDeleted::class, function ($event) {
// Handle record deletion
});
use Asciisd\Zoho\Traits\SyncsWithZoho;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use SyncsWithZoho;
protected $fillable = ['name', 'email', 'phone'];
/**
* Specify which Zoho module to sync with.
*/
protected function getZohoModule(): string
{
return 'Contacts';
}
}
// Automatically creates a Contact in Zoho CRM (queued)
$user = User::create([
'name' => 'John Doe',
'email' => '[email protected]',
'phone' => '+1234567890',
]);
// Automatically updates the Contact in Zoho CRM (queued)
$user->update(['phone' => '+0987654321']);
// Automatically deletes the Contact in Zoho CRM (queued)
$user->delete();
class User extends Authenticatable
{
use SyncsWithZoho;
protected $fillable = ['name', 'email', 'phone', 'company'];
protected function getZohoModule(): string
{
return 'Contacts';
}
/**
* Map Laravel model fields to Zoho CRM fields.
*/
protected function getZohoFieldMapping(): array
{
return [
'name' => 'Full_Name',
'email' => 'Email',
'phone' => 'Phone',
'company' => 'Account_Name',
];
}
}
use Asciisd\Zoho\Traits\SyncsWithZoho;
use Illuminate\Database\Eloquent\Model;
class DemoAccount extends Model
{
use SyncsWithZoho;
protected $fillable = [
'name',
'email',
'phone',
'country',
'company',
];
protected function getZohoModule(): string
{
return 'Leads';
}
protected function getZohoFieldMapping(): array
{
return [
'name' => 'Last_Name',
'email' => 'Email',
'phone' => 'Phone',
'company' => 'Company',
// 'country' will map automatically with the same name
];
}
}
protected function shouldSyncToZoho(): bool
{
// Only sync verified users
if ($this->email_verified_at === null) {
return false;
}
// Only sync users with specific role
if (!$this->hasRole('customer')) {
return false;
}
return parent::shouldSyncToZoho();
}
// Import data without syncing to Zoho
User::withoutZohoSync(function () {
User::create(['name' => 'John', 'email' => '[email protected]']);
User::create(['name' => 'Jane', 'email' => '[email protected]']);
// ... import 1000 more users
});
// Or disable for a single operation
User::withoutZohoSync(fn () => $user->update(['internal_notes' => 'test']));
// Force immediate sync to Zoho
$user->syncToZohoNow('create');
$user->syncToZohoNow('update');
$user = User::find(1);
// Get the Zoho record ID
$zohoRecordId = $user->getZohoRecordId();
// Access the full sync relationship
$zohoSync = $user->zohoSync;
echo $zohoSync->zoho_record_id;
echo $zohoSync->zoho_module;
echo $zohoSync->last_synced_at;
'sync' => [
// Enable or disable automatic syncing globally
'enabled' => env('ZOHO_SYNC_ENABLED', true),
// Queue connection to use for sync jobs
'queue' => env('ZOHO_SYNC_QUEUE', 'default'),
// Number of retry attempts
'retry_attempts' => env('ZOHO_SYNC_RETRY_ATTEMPTS', 3),
// Backoff delays between retries (in seconds)
'retry_backoff' => [60, 120, 300], // 1 min, 2 min, 5 min
],