- How do I install the Bitrix24 PHP SDK in a Laravel project?
- Use Composer to install the package with `composer require bitrix24/b24phpsdk`. For Laravel, register a service provider to bind the SDK to the container, typically in `config/app.php`. Configure credentials in `config/bitrix24.php` or `.env` for security.
- Which Laravel versions are compatible with this SDK?
- The SDK supports Laravel 9+ (PHP 8.2+) for v1 and Laravel 10+ (PHP 8.4+) for v3. Ensure your Laravel version aligns with the SDK’s PHP requirements. Check Laravel’s official documentation for supported PHP versions.
- What’s the difference between SDK v1 and v3 for Laravel?
- v1 is stable with no breaking changes, ideal for production. v3 introduces new API endpoints (e.g., `/rest/api/`) and features but requires PHP 8.4+. Choose v1 for stability or v3 for future-proofing if you’re comfortable with refactoring.
- Can I use this SDK with Laravel’s Eloquent models?
- The SDK returns raw Bitrix24 data. You’ll need to map responses to Eloquent models manually or create custom DTOs. For example, use Laravel’s `fill()` method or a mapper service to transform SDK responses into Eloquent instances.
- How do I handle authentication in Laravel with this SDK?
- Store your Bitrix24 token in `.env` (e.g., `BITRIX24_TOKEN`) and reference it in `config/bitrix24.php`. The SDK uses token-based auth by default. For OAuth2, extend Laravel’s Socialite or use the SDK’s `ApplicationProfile` with custom logic.
- Does the SDK support Laravel queues for rate-limited API calls?
- Yes. Use Laravel’s queue system to batch or retry failed requests. The SDK’s batching helps, but wrap heavy operations in jobs (e.g., `dispatch(new SyncCrmJob())`) to avoid rate limits and improve performance.
- How can I test the SDK in Laravel without hitting Bitrix24’s API?
- Mock the SDK’s `ApiClient` or `Services/*` in unit tests using Laravel’s `Mockery` or PHPUnit. For integration tests, use a Bitrix24 sandbox account. Avoid real API calls in CI by stubbing responses or using a local testing environment.
- Are there Laravel-specific extensions or packages for this SDK?
- The official SDK is generic PHP. For Laravel, consider building custom packages (e.g., `laravel-bitrix24/crm`) to wrap SDK services in Eloquent models, queue jobs, or Scout integrations. Check Packagist for community extensions.
- How do I handle errors or failed API requests in Laravel?
- The SDK throws exceptions based on Symfony’s `ResponseInterface`. Create a custom exception handler to log failures or notify users. For example, catch `Bitrix24Exception` and log it via Laravel’s log channel or send alerts.
- What are the alternatives to this SDK for Laravel?
- Alternatives include unofficial wrappers like `guzzlehttp/guzzle` with custom API logic or Bitrix24’s native JavaScript SDK for frontend integrations. However, this official SDK offers typed clients, better maintainability, and full API coverage for PHP/Laravel.