volldigital / laravel-navision
Requires
- php: ^7.2 || ^8.0 || ^8.1 || ^8.2
- laravel/framework: ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
This package is auto-updated.
Last update: 2025-03-29 01:00:55 UTC
README
A small package to communicate with Microsoft Navision. You can fetch collections and single records.
Install
Run following commands:
composer require volldigital/laravel-navision
php artisan vendor:publish --provider="VOLLdigital\LaravelNavision\LaravelNavisionServiceProvider"
Edit your "config/ntlm.php" file or use the ENV variables.
Usage
After setting up your config, load the client via:
$client = app(VOLLdigital\LaravelNavision\Client::class);
Now you are ready to recieve data from your Navision.
Examples:
$client = app(VOLLdigital\LaravelNavision\Client::class); $data = $client->fetchCollection("Events"); $event = $client->fetchOne("Events", 'Key', 'Number');
You can also pull data chunk-wise. The data will be written in a text file and after the request finished, it will be parsed and deleted.
$client = app(VOLLdigital\LaravelNavision\Client::class); // file will be stored in /storage/app/temp/curl_uniqueid.temp $data = $client->fetchCollection("Events", true);
You want to check if your connection to UNITOP is established? You can use the ping function and check it :)
$client = app(VOLLdigital\LaravelNavision\Client::class); if ($client->ping() === false) { throw new RunTimeException('No connection available'); }
Write data
Use $client->writeData(string $url, array $data);
to write data into navision.
Example:
$client->writeData( 'Items', [ 'Item_Code' => 'VD', 'Item_Description' => 'Test data' ] );
Count items
Use $client->countCollection("YourCollection")
to recieve the amount of items in this collection.
Example:
dd($client->countCollection('Events')); // Outputs: 100293
Examples
Query params
- $skip=XXXX - Skip X amount of itmes
$temp = $this->client->fetchCollection('Events?$skip=10000');
- $top=XXXX - Recieve X amount of items
$temp = $this->client->fetchCollection('Events?$top=10');
Fetching data
protected function fetchData(string $uri, $key, bool $chunk = false, ?callable $filter = null) { $temp = $this->client->fetchCollection($uri, $chunk); $data = []; foreach($temp as $ts) { if (!is_null($filter) && $filter($ts) === false) { continue; } $data[$ts[$key]] = $ts; } return collect($data); }
Pagination
protected function fetchAll() { $number = $this->client->countCollection('Events'); $pageLimit = 10000; $pages = (int)ceil($number / $pageLimit); $events = []; for ($i = 0; $i < $pages; $i++) { $skip = $i * $pageLimit; $temp = $this->fetchData('Events?$skip='.$skip, 'Number'); $events = array_merge($events, $temp->toArray()); } return collect($events); }