peter9x / laravel-bc
Laravel package for Microsoft Business Central API
v0.1.4
2026-07-22 21:37 UTC
Requires
- php: ^8.2
- ext-curl: *
- ext-fileinfo: *
- ext-json: *
- guzzlehttp/guzzle: 7.x
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- league/oauth2-client: ^2
Requires (Dev)
- laravel/pint: ^1.24
- orchestra/testbench: ^10.4|^11.0
- pestphp/pest: ^v2.34|^3.7
- phpunit/phpunit: ^11.5
- spatie/laravel-health: ^1.40
Suggests
- spatie/laravel-health: Allows monitoring Business Central connections via the Mupy\BusinessCentral\HealthChecks\BusinessCentralCheck health check (spatie/laravel-health).
README
Laravel Business Central
A Laravel package for integrating with the Microsoft Business Central API.
Installation
- Install the package via Composer:
composer require peter9x/laravel-bc
- Publish the configuration file:
php artisan vendor:publish --provider="Mupy\\BusinessCentral\\BusinessCentralServiceProvider" --tag=config
- Add the following to your
.envfile:
Note:
BC_COMPANY_IDis optional.
If not set, you will need to select a company in your code after retrieving the list of companies (see the usage example).
BC_CLIENT_ID=your-client-id BC_CLIENT_SECRET=your-client-secret BC_TENANT_ID=your-tenant-id # Optional: if not set, select the company in your script BC_COMPANY_ID=your-company-id BC_ENVIRONMENT=sandbox
Usage
use Mupy\BusinessCentral\Facades\BusinessCentral; use Mupy\BusinessCentral\EndPoint\Company; use Mupy\BusinessCentral\EndPoint\SalesInvoices; $api = BusinessCentral::getClient(); // Change the environment dynamically if needed $api->selectEnv('sandbox'); try { $result = $api->get(Company::class); if ($result->success()) { foreach ($result->data() as $entry) { // Select the company dynamically if BC_COMPANY_ID is not set in .env $company = $api->useCompany($entry['id']); $company->get(SalesInvoices::class); } } } catch (\Throwable $th) { // Handle exceptions as needed }
Health checks (optional)
If your application uses spatie/laravel-health, this package ships a
BusinessCentralCheck that verifies authentication against your configured Business Central connection(s).
- Install
spatie/laravel-healthin your application (not required by this package unless you use this feature):
composer require spatie/laravel-health
- Register the check, typically in
AppServiceProvider::boot():
use Mupy\BusinessCentral\HealthChecks\BusinessCentralCheck; use Spatie\Health\Facades\Health; Health::checks([ BusinessCentralCheck::new(), ]);
By default the check authenticates against every connection defined in config('businesscentral.connections').
To limit it to specific connections:
BusinessCentralCheck::new()->connections(['default']);