https://github.com/peter9x/laravel-bc
Laravel package for Microsoft Business Central API
https://github.com/peter9x/laravel-bc
businesscentral laravel microsoft
Last synced: 5 months ago
JSON representation
Laravel package for Microsoft Business Central API
- Host: GitHub
- URL: https://github.com/peter9x/laravel-bc
- Owner: peter9x
- License: gpl-3.0
- Created: 2025-08-13T17:05:10.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-17T15:23:17.000Z (9 months ago)
- Last Synced: 2025-10-26T03:53:53.291Z (8 months ago)
- Topics: businesscentral, laravel, microsoft
- Language: PHP
- Homepage:
- Size: 103 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Business Central
A Laravel package for integrating with the **Microsoft Business Central API**.
## Installation
1. Install the package via Composer:
```bash
composer require peter9x/laravel-bc
```
2. Publish the configuration file:
```bash
php artisan vendor:publish --provider="Mupy\\BusinessCentral\\BusinessCentralServiceProvider" --tag=config
```
3. Add the following to your `.env` file:
> **Note:** `BC_COMPANY_ID` is **optional**.
> If not set, you will need to select a company in your code after retrieving the list of companies (see the usage example).
```env
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
```php
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
}
```