A Laravel package providing DTOs and requests for integrating with M-Files REST API.
You can install the package via composer:
composer require codebar-ag/laravel-m-files
Publish the configuration file:
php artisan vendor:publish --provider="CodebarAg\MFiles\MFilesServiceProvider"
Add your M-Files authentication credentials to your .env
file:
M_FILES_URL=https://your-mfiles-server.com
M_FILES_USERNAME=your-username
M_FILES_PASSWORD=your-password
M_FILES_IDENTIFIER=default
M_FILES_VAULT_GUID=ABC0DE2G-3HW-QWCQ-SDF3-WERWETWETW
M_FILES_CACHE_DRIVER=file
GetAuthenticationToken
- Get authentication token using username/passwordLogoutSession
- Logout a session with session ID
GetCurrentUserRequest
- Get information about the current authenticated user
GetDocumentsRequest
- Get documents with optional filteringGetDocumentPropertiesRequest
- Get document properties
UploadFileRequest
- Upload a file to M-FilesCreateSingleFileDocumentRequest
- Create a single file documentDownloadFileRequest
- Download a file from M-Files
MFDataTypeEnum
- Represents a data type in M-Files
Property
- Represents a property in M-FilesPropertyValue
- Represents a property value for creating documentsDocument
- Represents a document in M-FilesDocuments
- Represents a collection of documentsFile
- Represents a file in M-FilesDownloadedFile
- Represents a downloaded file with content and metadataUser
- Represents a user in M-Files
use CodebarAg\MFiles\Connectors\MFilesConnector;
use CodebarAg\MFiles\DTO\Config\ConfigWithCredentials;
$config = new ConfigWithCredentials();
// or for multi tenant applications
$config = new ConfigWithCredentials(
url: 'https://your-mfiles-server.com',
username: 'your-username',
password: 'your-password',
identifier: 'default',
cacheDriver: 'file',
requestTimeoutInSeconds: 15,
vaultGuid: 'ABC0DE2G-3HW-QWCQ-SDF3-WERWETWETW',
authenticationToken: null // Optional to handle authentication manually, leave null to use automatic token management
);
$connector = new MFilesConnector(config: $config);
By default authentication is handled automatically, to disable this, pass
authenticationToken: null
to the ConfigWithCredentials dto.
Get Authentication Token
use CodebarAg\MFiles\Requests\Authentication\GetAuthenticationToken;
use CodebarAg\MFiles\DTO\Authentication\AuthenticationToken;
$request = new GetAuthenticationToken(
url: 'https://your-mfiles-server.com',
username: 'your-username',
password: 'your-password',
vaultGuid: 'ABC0DE2G-3HW-QWCQ-SDF3-WERWETWETW'
);
$token = $request->send()->dto();
// Returns AuthenticationToken with sessionId
Logout Session
use CodebarAg\MFiles\Requests\Authentication\LogoutSession;
$logout = (new LogoutSession(config: $config))->send()->dto();
// Returns true on successful logout, clears cached token
Get Current User
use CodebarAg\MFiles\Requests\GetCurrentUserRequest;
use CodebarAg\MFiles\DTO\User;
$user = $connector->send(new GetCurrentUserRequest())->dto();
// Returns User DTO with id, name, email, etc.
Get Documents
use CodebarAg\MFiles\Requests\GetDocumentsRequest;
use CodebarAg\MFiles\DTO\Documents;
$documents = $connector->send(new GetDocumentsRequest())->dto();
// Returns Documents collection with pagination info
// With filtering parameters
$documents = $connector->send(new GetDocumentsRequest(
page: 1,
pageSize: 5,
searchString: 'Sample',
objectTypeId: 0,
includeDeleted: false,
includeSubfolders: true,
sortBy: 'Title',
sortDirection: 'asc'
))->dto();
Get Document Properties
use CodebarAg\MFiles\Requests\GetDocumentPropertiesRequest;
use CodebarAg\MFiles\DTO\DocumentProperties;
$properties = $connector->send(new GetDocumentPropertiesRequest(
objectId: 123
))->dto();
// Returns DocumentProperties with property details
// With optional parameters
$properties = $connector->send(new GetDocumentPropertiesRequest(
objectId: 123,
objectTypeId: 0,
includeDeleted: false
))->dto();
Upload File
use CodebarAg\MFiles\Requests\UploadFileRequest;
$fileContent = file_get_contents('path/to/file.pdf');
$fileName = 'document.pdf';
$uploadedFile = $connector->send(new UploadFileRequest(
fileContent: $fileContent,
fileName: $fileName
))->dto();
// Returns array with file ID, title, extension
Create Single File Document
use CodebarAg\MFiles\Requests\CreateSingleFileDocumentRequest;
use CodebarAg\MFiles\DTO\PropertyValue;
use CodebarAg\MFiles\Enums\MFDataTypeEnum;
use CodebarAg\MFiles\DTO\Document;
// First upload the file
$uploadedFile = $connector->send(new UploadFileRequest(
fileContent: $fileContent,
fileName: 'document.pdf'
))->dto();
// Then create the document
$document = $connector->send(new CreateSingleFileDocumentRequest(
title: 'My Document',
file: $uploadedFile
))->dto();
// Returns Document DTO with id, title, files, etc.
// With custom property values
$propertyValues = [
new PropertyValue(propertyDef: 0, dataType: MFDataTypeEnum::TEXT, value: 'Custom Title'),
new PropertyValue(propertyDef: 5, dataType: MFDataTypeEnum::DATE, value: '2024-01-01'),
];
$document = $connector->send(new CreateSingleFileDocumentRequest(
title: 'Custom Document',
file: $uploadedFile,
propertyValues: $propertyValues
))->dto();
Download File
use CodebarAg\MFiles\Requests\DownloadFileRequest;
use CodebarAg\MFiles\DTO\DownloadedFile;
$downloadedFile = $connector->send(new DownloadFileRequest(
objectId: 123,
fileId: 456
))->dto();
// Returns DownloadedFile with content, name, extension, size, contentType
// With optional parameters
$downloadedFile = $connector->send(new DownloadFileRequest(
objectId: 123,
fileId: 456,
objectTypeId: 0,
includeDeleted: false
))->dto();
use CodebarAg\MFiles\Connectors\MFilesConnector;
use CodebarAg\MFiles\DTO\Config\ConfigWithCredentials;
use CodebarAg\MFiles\Requests\GetCurrentUserRequest;
use CodebarAg\MFiles\Requests\GetDocumentsRequest;
use CodebarAg\MFiles\Requests\CreateSingleFileDocumentRequest;
use CodebarAg\MFiles\Requests\UploadFileRequest;
use CodebarAg\MFiles\Requests\DownloadFileRequest;
use CodebarAg\MFiles\DTO\PropertyValue;
use CodebarAg\MFiles\Enums\MFDataTypeEnum;
$config = new ConfigWithCredentials(
url: 'https://your-mfiles-server.com',
username: 'your-username',
password: 'your-password',
identifier: 'default',
cacheDriver: 'file',
requestTimeoutInSeconds: 15,
vaultGuid: 'ABC0DE2G-3HW-QWCQ-SDF3-WERWETWETW'
);
$connector = new MFilesConnector(config: $config);
// Get current user
$user = $connector->send(new GetCurrentUserRequest())->dto();
// Get documents
$documents = $connector->send(new GetDocumentsRequest())->dto();
// Upload a file
$fileContent = file_get_contents('document.pdf');
$uploadedFile = $connector->send(new UploadFileRequest(
fileContent: $fileContent,
fileName: 'document.pdf'
))->dto();
// Create a document with the uploaded file
$document = $connector->send(new CreateSingleFileDocumentRequest(
title: 'My Document',
file: $uploadedFile,
propertyValues: [
new PropertyValue(propertyDef: 0, dataType: MFDataTypeEnum::TEXT, value: 'Custom Title'),
new PropertyValue(propertyDef: 5, dataType: MFDataTypeEnum::DATE, value: '2024-01-01'),
]
))->dto();
// Download a file from a document
$file = $document->files->first();
$downloadedFile = $connector->send(new DownloadFileRequest(
objectId: $document->id,
fileId: $file->id
))->dto();
The package supports M-Files authentication tokens with automatic token management:
- Automatic Token Generation: Tokens are automatically generated using username/password
- Token Caching: Tokens are cached to reduce API calls
- Flexible Configuration: Support for multiple configurations through
ConfigWithCredentials
For applications that need to connect to multiple M-Files instances, you can manage different configurations by creating separate ConfigWithCredentials
instances.
You can store these configurations in your application's configuration files, environment variables, or database.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.