A Laravel SDK for SAP Business One Service Layer. Handles sessions, builds OData queries, manages connections, and gets out of your way.
use SapB1\Facades\SapB1;
// It just works
$partners = SapB1::get('BusinessPartners')->value();
// Query builder for complex stuff
$orders = SapB1::query()
->select('DocEntry', 'DocNum', 'CardCode', 'DocTotal')
->where('DocDate', 'ge', '2024-01-01')
->whereContains('CardName', 'Corp')
->orderByDesc('DocDate')
->expand('DocumentLines')
->get('Orders')
->value();
// CRUD operations
SapB1::create('BusinessPartners', ['CardCode' => 'C001', 'CardName' => 'Acme Corp']);
SapB1::update('BusinessPartners', 'C001', ['Phone1' => '555-1234']);
SapB1::delete('BusinessPartners', 'C001');composer require ismaildasci/laravel-sapb1
php artisan vendor:publish --tag="sap-b1-config"Add to .env:
SAP_B1_URL=https://your-sap-server:50000
SAP_B1_COMPANY_DB=YOUR_COMPANY_DB
SAP_B1_USERNAME=manager
SAP_B1_PASSWORD=your_passwordFull documentation is available in the docs folder:
Getting Started
- Quick Start - Get up and running in minutes
- Installation & Configuration
Core Concepts
- Making Requests - CRUD operations & request methods
- OData Query Builder - Fluent query building
- Working with Responses - Response handling & pagination
- Multiple Connections - Multi-server setup
Features
- Batch Operations - Multiple requests in one call
- Session Pool - High-concurrency scenarios
- Circuit Breaker - Resilience & fault tolerance
- Query Caching - Performance optimization
- Attachments - File uploads & downloads
- SQL Queries - Stored queries & semantic layer
- Multi-Tenant - Multi-tenant session isolation
Operations & Debugging
- Health Checks - Connection monitoring
- Artisan Commands - CLI tools
- Events - Event lifecycle & listeners
- Error Handling - Exceptions & error codes
Testing
- Testing - Mocking & factories
- Testing Factories - Entity factory patterns
Core - Fluent OData query builder, automatic session management, multiple connections, rich response handling, request middleware pipeline.
Performance - Batch operations, query caching, request compression, connection pooling, schema caching.
Resilience - Circuit breaker pattern, automatic retries with exponential backoff, session auto-refresh, rate limit handling, human-readable error messages.
Observability - OpenTelemetry integration, connection diagnostics, query profiling, change detection.
Enterprise - Multi-tenant session isolation, audit trail access, alert management, company info API.
Operations - Artisan commands for status, health checks, session management, and pool administration.
Testing - SapB1Fake trait, FakeResponse builder, entity factories for BusinessPartner, Item, and Order.
// Use different SAP B1 servers
$response = SapB1::connection('production')->get('Items');
$response = sap_b1('staging')->get('Items');$batch = SapB1::batch();
$batch->get('BusinessPartners', 'C001');
$batch->beginChangeset();
$batch->post('Orders', $orderData);
$batch->patch('Items', 'A001', ['ItemName' => 'Updated']);
$batch->endChangeset();
$responses = $batch->execute();// SAP deprecated OData v3 in FP 2405
$response = SapB1::useODataV4()->get('Items');// Watch for order changes (alternative to webhooks)
$detector = SapB1::changes();
$detector->watch('Orders')
->track('DocStatus', 'DocTotal')
->onCreated(fn($order) => dispatch(new NewOrderJob($order)))
->onUpdated(fn($order, $changes) => Log::info('Order updated', $changes));
$changes = $detector->poll(); // Run periodically// Introspect SAP B1 entities
$entities = SapB1::metadata()->entities();
$schema = SapB1::metadata()->entity('BusinessPartners');
$udfs = SapB1::metadata()->udfs('OCRD'); // User Defined Fields// Tenant-specific connections
app(TenantManager::class)->forTenant('tenant-123', function() {
return SapB1::get('Orders')->value();
});php artisan sap-b1:status --test
php artisan sap-b1:health --all
php artisan sap-b1:pool status- PHP 8.4+
- Laravel 11.x or 12.x
- SAP Business One with Service Layer
composer testSee CHANGELOG for recent changes.
See CONTRIBUTING for details.
Report vulnerabilities via security policy.
MIT License. See LICENSE.