Download the PHP package yehia-tarek/laravel-erpnext without Composer
On this page you can find all versions of the php package yehia-tarek/laravel-erpnext. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-erpnext
Laravel ERPNext
A robust, fluent Laravel package for seamlessly interacting with the ERPNext / Frappe REST API. It provides an elegant interface for CRUD operations, a powerful query builder, typed document resources, file uploads, and multiple authentication strategies.
📋 Table of Contents
- Requirements
- Installation
- Configuration
- Authentication
- Quick Start
- Usage
- CRUD Operations
- Fluent Query Builder
- Remote Method Calls
- File Uploads
- Advanced Features
- Typed Document Resources
- Multiple Connections
- Error Handling
- Testing
- License
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.1 |
| Laravel | ^10.0 or ^11.0 |
| Guzzle | ^7.5 |
Installation
You can install the package via Composer:
Publish the configuration file to define your ERPNext connection settings:
Configuration
Add your ERPNext credentials to your application's .env file. The package supports multiple authentication methods, with Token Authentication being the recommended approach for API integrations.
Generating API Keys in ERPNext
To use Token Authentication, generate API keys from your ERPNext instance:
- Go to User List → open the desired user.
- Click on the Settings tab.
- Expand the API Access section and click Generate Keys.
- Copy the API Secret immediately (it is only shown once).
- Note the API Key displayed in the same section.
Authentication
The package automatically handles authentication based on your .env configuration.
- Token: Sends
Authorization: token {api_key}:{api_secret}with every request. - Password: Performs a login request on the first API call and reuses the returned cookie session for subsequent requests.
- OAuth 2.0: Sends
Authorization: Bearer {access_token}with every request.
Quick Start
After configuring your .env file, you can verify the connection using the ERPNext facade:
Usage
CRUD Operations
The package provides intuitive methods to interact with ERPNext documents.
Create a Document
Read a Document
Update a Document
Delete a Document
Fluent Query Builder
Retrieve multiple documents using a fluent, Eloquent-like query builder that wraps the GET /api/resource/:doctype endpoint.
Available Builder Methods
| Method | Description |
|---|---|
fields(array) |
Specify which fields to fetch. |
filter(field, op, value) |
Add an AND filter condition. |
filters(array) |
Add multiple AND filters at once. |
orFilter(field, op, value) |
Add an OR filter condition. |
expand(array) |
Expand specific link fields inline. |
orderBy(field, direction) |
Sort results (asc or desc). |
limit(int) |
Limit the number of records returned. |
offset(int) |
Skip a specific number of records. |
paginate(page, perPage) |
Utilize page-based pagination. |
asList() |
Return results as a List[List] instead of List[dict]. |
debug() |
Include executed SQL in the response. |
get() |
Execute the query and return an array. |
first() |
Execute and return the first item or null. |
count() |
Return the total count of matching documents. |
Supported Filtering Operators
Remote Method Calls
Call any whitelisted Python method on your ERPNext instance.
File Uploads
Upload files directly from your local filesystem or via raw content.
Upload from Local Path
Upload from Raw Content
Advanced Features
Typed Document Resources
For a more structured, object-oriented approach, you can define typed resources that extend the base Document class. This provides an Eloquent-like experience for specific DocTypes.
Usage Example:
Multiple Connections
If you need to interact with multiple ERPNext instances (e.g., staging and production), define them in config/erpnext.php:
You can easily switch connections using the connection() method:
Error Handling
The package throws specific exceptions for different API error scenarios, allowing you to handle them gracefully.
| Exception | Trigger |
|---|---|
AuthenticationException |
401/403 responses or missing credentials. |
DocumentNotFoundException |
404 response from ERPNext. |
ValidationException |
ERPNext ValidationError (422). |
ERPNextException |
Fallback for all other API errors. |
Example:
Testing
Run the package tests using Composer:
Mocking in Your Application Tests
You can easily mock the ERPNext facade in your application's test suite:
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of laravel-erpnext with dependencies
guzzlehttp/guzzle Version ^7.5
illuminate/support Version ^10.0|^11.0|^12.0|^13.0