Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sugar7Wrapper Laravel Package

spinegar/sugar7wrapper

Laravel wrapper for SugarCRM 7 REST API. Provides a clean PHP client with authentication helpers and convenient methods for common CRM operations like querying and updating records, making Sugar 7 integration quicker and more maintainable.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require spinegar/sugar7wrapper
    

    Add to config/app.php under providers:

    Spinegar\Sugar7Wrapper\Sugar7WrapperServiceProvider::class,
    
  2. Configuration Publish the config file:

    php artisan vendor:publish --provider="Spinegar\Sugar7Wrapper\Sugar7WrapperServiceProvider"
    

    Update .env with your SugarCRM credentials:

    SUGARCRM_URL=https://your-sugar-instance.com
    SUGARCRM_USERNAME=your_username
    SUGARCRM_PASSWORD=your_password
    
  3. First Use Case: Fetching a Record

    use Spinegar\Sugar7Wrapper\Facades\Sugar7Wrapper;
    
    $account = Sugar7Wrapper::get('Accounts', 1); // Fetch Account ID 1
    dd($account);
    

Implementation Patterns

Common Workflows

  1. CRUD Operations

    // Create
    $newAccount = Sugar7Wrapper::create('Accounts', [
        'name' => 'New Company',
        'description' => 'Test account'
    ]);
    
    // Update
    $updatedAccount = Sugar7Wrapper::update('Accounts', 1, [
        'description' => 'Updated description'
    ]);
    
    // Delete
    Sugar7Wrapper::delete('Accounts', 1);
    
  2. Querying with Filters

    $accounts = Sugar7Wrapper::query('Accounts')
        ->filter(['name' => 'Test'])
        ->limit(10)
        ->get();
    
  3. Relationships

    $accountWithContacts = Sugar7Wrapper::get('Accounts', 1, ['contacts']);
    
  4. Bulk Operations

    $ids = [1, 2, 3];
    $accounts = Sugar7Wrapper::getMultiple('Accounts', $ids);
    

Integration Tips

  • Laravel Eloquent Integration Use the facade in Eloquent models for direct SugarCRM access:

    class AccountModel extends Model {
        public function fetchFromSugar($id) {
            return Sugar7Wrapper::get('Accounts', $id);
        }
    }
    
  • Event Listeners Sync SugarCRM data on model events:

    public function created(Account $account) {
        Sugar7Wrapper::create('Accounts', $account->toArray());
    }
    
  • API Resource Transformation Convert SugarCRM responses to Laravel API Resources:

    public function toArray($request) {
        $sugarData = Sugar7Wrapper::get('Accounts', $this->id);
        return [
            'name' => $sugarData['name'],
            'description' => $sugarData['description']
        ];
    }
    

Gotchas and Tips

Pitfalls

  1. Authentication Issues

    • Ensure .env credentials are correct and the SugarCRM REST API is enabled.
    • Check for IP restrictions or OAuth requirements in SugarCRM settings.
  2. Rate Limiting

    • SugarCRM may throttle requests. Implement retries with exponential backoff:
      try {
          $data = Sugar7Wrapper::get('Accounts', 1);
      } catch (\Exception $e) {
          if ($e->getCode() === 429) {
              sleep(2);
              retry();
          }
      }
      
  3. Field Mapping

    • SugarCRM uses custom field names (e.g., account_name instead of name). Verify field names via SugarCRM’s REST API docs or the describe method:
      $fields = Sugar7Wrapper::describe('Accounts');
      
  4. Timeouts

    • Large queries may timeout. Use chunking:
      $accounts = Sugar7Wrapper::query('Accounts')->limit(100)->get();
      

Debugging

  • Enable Logging Add to config/sugar7wrapper.php:

    'debug' => env('APP_DEBUG', false),
    

    Check logs for failed requests.

  • Raw Response Inspection Use the raw() method to debug API responses:

    $response = Sugar7Wrapper::get('Accounts', 1, [], true);
    dd($response);
    

Extension Points

  1. Custom Endpoints Extend the wrapper for non-standard SugarCRM endpoints:

    Sugar7Wrapper::customRequest('GET', '/api/v11/rest.php', [
        'method' => 'getEntryPoint',
        'input' => ['module' => 'CustomModule']
    ]);
    
  2. Middleware Add request/response middleware:

    Sugar7Wrapper::withMiddleware(function ($request) {
        $request->headers->set('X-Custom-Header', 'value');
    });
    
  3. Caching Cache frequent queries using Laravel’s cache:

    $account = cache()->remember("sugar_account_{$id}", now()->addHours(1), function () use ($id) {
        return Sugar7Wrapper::get('Accounts', $id);
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor