A middleware package to provide ERP functionality to Robodocxs
robodocxs/laravel-erp-middleware is a Laravel package for a middleware package to provide erp functionality to robodocxs.
It currently has 0 GitHub stars and 82 downloads on Packagist (latest version 2.0.1).
Install it with composer require robodocxs/laravel-erp-middleware.
Discover more Laravel packages by robodocxs
or browse all Laravel packages to compare alternatives.
Last updated
This package provides a middleware for ERP integration in Laravel applications, including basic DTOs, custom middleware for one-time basic authentication, custom exception handling, and additional capabilities for SFTP file system operations and CSV handling.
Only if you want to start from a new laravel project:
php artisan laravel new robodocxs-middleware-something
Install the package via composer:
composer require robodocxs/laravel-erp-middleware
After installation, you should publish the configuration file:
php artisan vendor:publish --provider="Robodocxs\LaravelErpMiddleware\LaravelErpMiddlewareServiceProvider" --tag="config"
This will publish the robodocxs-erp-middleware.php configuration file to your config directory.
Then, install the api:
php artisan api:install
Use this example routes file:
Route::middleware('auth.basic.once')->group(function () {
Route::get('/products', [LaravelErpMiddlewareController::class, 'listProducts'])
->name('products.index');
Route::get('/accounts', [LaravelErpMiddlewareController::class, 'listAccounts'])
->name('accounts.index');
Route::get('/accounts/{account_id}/contacts', [LaravelErpMiddlewareController::class, 'listAccountContacts'])
->name('accounts.contacts');
Route::get('/accounts/{account_id}/addresses', [LaravelErpMiddlewareController::class, 'listAccountAddresses'])
->name('accounts.addresses');
Route::get('/accounts/{account_id}/products', [LaravelErpMiddlewareController::class, 'listAccountCustomProducts'])
->name('accounts.products');
Route::post('/products/price-and-availability', [LaravelErpMiddlewareController::class, 'checkPriceAndAvailability'])
->name('products.price-availability');
Route::get('/ping', [LaravelErpMiddlewareController::class, 'ping'])
->name('ping');
});
To publish the built-in Controller as a starting point, use this command:
laravel-erp-middleware:publish-api-controller
If you need SFTP access, add the following disk to config/filesystems.php file directly:
'fileshare' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
'username' => env('SFTP_USERNAME'),
'password' => env('SFTP_PASSWORD'),
'privateKey' => env('SFTP_PRIVATE_KEY'),
'passphrase' => env('SFTP_PASSPHRASE'),
'root' => env('SFTP_ROOT'),
'visibility' => 'private', // `private` = 0600, `public` = 0644
'directory_visibility' => 'private', // `private` = 0700, `public` = 0755
// 'hostFingerprint' => env('SFTP_HOST_FINGERPRINT'),
// 'maxTries' => 4,
// 'passphrase' => env('SFTP_PASSPHRASE'),
// 'port' => env('SFTP_PORT', 22),
// 'root' => env('SFTP_ROOT', ''),
// 'timeout' => 30,
// 'useAgent' => true,
// Setting for the environment
]
Then add the following keys to your env to use the disk:
SFTP_HOST=your_sftp_host
SFTP_USERNAME=your_username
SFTP_PASSWORD=your_password
SFTP_PRIVATE_KEY=path_to_your_private_key
SFTP_PASSPHRASE=your_passphrase
SFTP_ROOT=/home/someuser
This package provides pre-defined API routes and a middleware controller to handle them. All routes are protected by the AuthenticateOnceWithBasicAuth middleware, which implements one-time basic authentication.
The following routes are available:
GET /api/productssearch (optional)GET /api/accountsname, vat_id (both optional)GET /api/accounts/{account_id}/contactsGET /api/accounts/{account_id}/addressesGET /api/accounts/{account_id}/productsPOST /api/accounts/{account_id}/erp-documentsPOST /api/products/price-and-availabilityAll these routes require authentication. The AuthenticateOnceWithBasicAuth middleware will prompt for credentials on the first request and then allow subsequent requests without re-authentication for a limited time.
This package requires DTOs from robodocxs/robodocxs-middleware-dtos. They serve as the glue between the backend and the middlewares.
This package includes a middleware for one-time basic authentication. It's automatically applied to all API routes provided by this package. If you want to use it in your own routes, you can do so like this:
Route::get('/api/example', function () {
// Your protected route logic here
})->middleware('auth.basic.once');
This package configures a new 'fileshare' disk for SFTP operations. After publishing and configuring the sftp.php config file, you can use it like this:
use Illuminate\Support\Facades\Storage;
$disk = Storage::disk('fileshare');
// Now you can use $disk to perform SFTP operations
$contents = $disk->get('file.txt');
$disk->put('file.txt', 'Contents');
This package includes the league/csv package for CSV operations. Here's a basic example of reading a CSV file:
use League\Csv\Reader;
$csv = Reader::createFromPath('/path/to/your/csv/file.csv', 'r');
$csv->setHeaderOffset(0);
foreach ($csv as $record) {
// Process each record
}
For more detailed usage instructions for SFTP and CSV operations, please refer to the respective package documentation:
When deploying to dev or prod servers, use these defaults for .env:
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis
CACHE_STORE=redis
CACHE_PREFIX="${APP_NAME}"
REDIS_DB=<see robodocxs/docs/middleware-server.md for allocation>
To run the package tests, use:
composer test
To symlink this project in your local middleware for faster development, follow these steps:
composer.json"repositories": [
{
"type": "path",
"url": "../laravel-erp-middleware",
"options": {
"symlink": true
}
}
]
dev-main and prefer source:composer require robodocxs/laravel-erp-middleware:dev-main --prefer-source
If you want to also symlink robodocxs/robodocxs-middleware-dtos in your project, you have to do it directly in that project. It is not possible to symlink it here and expect your project to pick it up from here.
Contributions are welcome! Please feel free to submit a Pull Request.
The MIT License (MIT).