borwita-packages/php-minio-service
Laravel/PHP helper for working with MinIO object storage. Provides a service wrapper to configure MinIO/S3-compatible connections and simplify common operations like uploads, downloads, and file management within your application.
Installation
composer require borwita-packages/php-minio-service
Publish Configuration
php artisan vendor:publish --provider="Borwita\MinioService\MinioServiceProvider" --tag="config"
config/minio-service.php with your MinIO endpoint, credentials, and bucket settings.First Use Case: Upload a File
use Borwita\MinioService\Facades\MinioService;
$filePath = 'path/to/local/file.jpg';
$objectName = 'uploaded/' . time() . '_file.jpg';
MinioService::uploadFile($filePath, $objectName);
endpoint: MinIO server URL (e.g., http://localhost:9000).access_key/secret_key: MinIO credentials.bucket: Default bucket name (or configure per-operation).use_ssl: Enable/disable SSL.MinioService::uploadFile($localPath, $objectName, ['bucket' => 'custom-bucket']);
$fileContent = MinioService::downloadFile($objectName, ['bucket' => 'custom-bucket']);
file_put_contents('local-path', $fileContent);
MinioService::deleteFile($objectName);
MinioService::ensureBucketExists('new-bucket');
$objects = MinioService::listObjects('bucket-name');
$url = MinioService::getPresignedUrl(
$objectName,
'GET',
'+1 hour', // Expiry time
['bucket' => 'private-bucket']
);
Configure filesystems.php to use the package:
'disks' => [
'minio' => [
'driver' => 'minio',
'bucket' => env('MINIO_BUCKET'),
],
],
Then use Laravel’s Storage facade:
Storage::disk('minio')->put('file.jpg', file_get_contents('local.jpg'));
Override default MinIO client settings per request:
MinioService::uploadFile($filePath, $objectName, [
'bucket' => 'custom-bucket',
'client_options' => [
'region' => 'us-east-1',
'endpoint' => 'https://custom-minio.example.com',
],
]);
Bucket Existence
ensureBucketExists() or handle BucketAlreadyExists/BucketNotFound exceptions.try {
MinioService::ensureBucketExists('my-bucket');
} catch (\Borwita\MinioService\Exceptions\BucketExists $e) {
// Bucket already exists; proceed.
}
Permissions
readwrite for buckets).mc admin policy list (MinIO CLI) if issues arise.SSL/TLS
MinioService::setClientOptions([
'ssl' => [
'verify_peer' => true,
'cafile' => '/path/to/ca-cert.pem',
],
]);
Large Files
$uploadId = MinioService::startMultipartUpload($objectName);
MinioService::uploadPart($uploadId, $filePath, 1);
MinioService::completeMultipartUpload($uploadId, [$objectName]);
Caching Presigned URLs
MinioService::setDebug(true); // Logs MinIO client requests/responses.
mc admin service log show (MinIO CLI) to inspect server-side errors.Custom Storage Adapter
Extend \Borwita\MinioService\Contracts\MinioServiceContract to add custom logic (e.g., metadata handling).
Events
Listen for file operations via Laravel events (e.g., minio.file.uploaded).
Middleware Add middleware to the MinIO client for logging/auditing:
MinioService::setClientMiddleware(function ($request) {
logger()->info('MinIO Request:', $request->getData());
});
MinioService::batchOperations() for multiple file actions (e.g., delete).spatie/async package).How can I help you explore Laravel packages today?