ismaildasci/laravel-sapb1

A Laravel package for SAP Business One Service Layer API integration

Fund package maintenance!
ismaildasci

Installs: 276

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/ismaildasci/laravel-sapb1

v1.8.0 2026-01-09 19:44 UTC

This package is auto-updated.

Last update: 2026-01-11 20:07:59 UTC


README

Latest Version on Packagist GitHub Tests Action Status PHPStan Total Downloads

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');

Installation

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_password

Documentation

Full documentation is available in the docs folder:

Getting Started

Core Concepts

Features

Operations & Debugging

Testing

Features

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.

Quick Examples

Multiple Connections

// Use different SAP B1 servers
$response = SapB1::connection('production')->get('Items');
$response = sap_b1('staging')->get('Items');

Batch Operations

$batch = SapB1::batch();
$batch->get('BusinessPartners', 'C001');
$batch->beginChangeset();
$batch->post('Orders', $orderData);
$batch->patch('Items', 'A001', ['ItemName' => 'Updated']);
$batch->endChangeset();
$responses = $batch->execute();

OData v4 Support

// SAP deprecated OData v3 in FP 2405
$response = SapB1::useODataV4()->get('Items');

Change Detection

// 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

Schema Discovery

// Introspect SAP B1 entities
$entities = SapB1::metadata()->entities();
$schema = SapB1::metadata()->entity('BusinessPartners');
$udfs = SapB1::metadata()->udfs('OCRD'); // User Defined Fields

Multi-Tenant

// Tenant-specific connections
app(TenantManager::class)->forTenant('tenant-123', function() {
    return SapB1::get('Orders')->value();
});

Health Monitoring

php artisan sap-b1:status --test
php artisan sap-b1:health --all
php artisan sap-b1:pool status

Requirements

  • PHP 8.4+
  • Laravel 11.x or 12.x
  • SAP Business One with Service Layer

Testing

composer test

Changelog

See CHANGELOG for recent changes.

Contributing

See CONTRIBUTING for details.

Security

Report vulnerabilities via security policy.

Credits

License

MIT License. See LICENSE.