flinty916/laravel-salesforce
Composer 安装命令:
composer require flinty916/laravel-salesforce
包简介
Salesforce Integration package for the Laravel framework
README 文档
README
This package provides a streamlined way to integrate Salesforce objects into your Laravel application.
It includes a custom query builder, model base class, and an Artisan command to automatically generate strongly-typed PHP classes for your Salesforce SObjects.
Installation
Install via Composer:
composer require flinty916/laravel-salesforce
Environment Variables
Before using the package, you must configure your Salesforce credentials in your Laravel .env file:
| Variable | Description |
|---|---|
SALESFORCE_CLIENT_ID |
The Consumer Key from your Salesforce Connected App. |
SALESFORCE_CLIENT_SECRET |
The Consumer Secret from your Salesforce Connected App. |
SALESFORCE_USERNAME |
Salesforce username used for authentication. |
SALESFORCE_PASSWORD |
Salesforce password plus security token (if required). |
SALESFORCE_LOGIN_URL |
Salesforce login URL — usually https://login.salesforce.com (production) or https://test.salesforce.com (sandbox). |
SALESFORCE_GRANT_TYPE |
Salesforce grant_type - currently supports password flow (legacy) and client_credentials |
SALESFORCE_API_VERSION |
Salesforce API version to use. Defaults to 58.0 |
Example .env
SALESFORCE_CLIENT_ID=your-client-id SALESFORCE_CLIENT_SECRET=your-client-secret SALESFORCE_USERNAME=your-username // password grant type only SALESFORCE_PASSWORD=your-password-and-token // password grant type only SALESFORCE_LOGIN_URL=https://login.salesforce.com SALESFORCE_GRANT_TYPE=client_credentials
Generating Salesforce Objects
This package ships with an Artisan command to generate PHP classes for your Salesforce SObjects.
All Objects
php artisan salesforce:generate-objects
This will connect to your Salesforce instance, retrieve all available objects, and create corresponding PHP classes in the app/SalesforceObjects directory. Please be warned, if you have a large salesforce instance, with lots of objects, this will be a long running command. I recommend you generate specific objects only (as shown below).
Specific Objects
You can limit generation to one or more objects using the --objects option:
php artisan salesforce:generate-objects --objects=Account,Contact,Opportunity
This will only generate classes for the specified Salesforce Objects.
Example Usage
Once an object has been generated, you can make use of Eloquent style operations.
Create an Object
$contact = Contact::create([ 'Name' => 'Test Contact' ]); // $contact will be type Contact, with the Id field populated only.
List Objects
Contact::fields(['Id', 'Email', 'Name__c',]) // Use fields() to specify limited field sets for queries ->where('Email', 'LIKE', 'maurice%') ->orWhere('Id', '=', '003D000002TND2QIAX') ->all() // Fetches ALL records, includes pagination handling for Salesforce 2000 row pages. ->records() // Returns collection of Contact;
Contact::fields(['Id', 'Email', 'Name__c',]) // Use fields() to specify limited field sets for queries ->where('Email', 'LIKE', 'maurice%') ->orWhere('Id', '=', '003D000002TND2QIAX') ->limit(20) // Set a hard limit. orderBy methods available as well. ->get() // Fetches without handling pages. ->records() // Returns collection of Contact;
Find an Object
Contact::find('MyId'); // Returns an instance of Contact, runs FIELDS(ALL) behind the scenes.
Update an Object
$contact = Contact::find('MyId'); $contact->update([ 'Name__c' => 'New Name' ]); // Returns no new data. Suggest a refetch/find operation afterwards to update state.
Delete an Object
$contact = Contact::find('MyId'); $contact->delete(); // Returns null
Describe an Object
Occasionally you'll need to obtain the metadata of an object, including Picklist values, fields, and more. This
is the use case for the describe method, which returns the API response from a salesforce sobject/<object>/describe
request.
$description = Contact::describe(); // Returns SalesforceDescription $myPicklistValues = $description->fields->where('name', 'myField')->first()->picklistValues; // returns Collection of SalesforcePicklistValue
## Working with Chatter Feeds
This package includes first-class support for Salesforce Chatter feeds, allowing you to retrieve, post, update, and comment on feed items related to any Salesforce record (e.g., an Opportunity, Account, or Case).
### Retrieving Feed Items
You can access a record’s chatter feed through the chatter() helper:
$opportunity = Opportunity::find('0068d00000ABC123'); $feed = $opportunity->chatter()->all(); // Returns a collection of feed elements (posts, comments, files, etc.) foreach ($feed as $element) { echo $element['actor']['displayName'] . ': ' . $element['body']['text']; }
Under the hood, this calls the Salesforce Chatter REST API:
GET /services/data/v{api_version}/chatter/feeds/record/{recordId}/feed-elements
and automatically maps the response into PHP objects for easy access.
Posting a New Message
To create a new post on a record’s feed, call post():
$opportunity->chatter()->post('We should increase the deal size to £200k.');
This issues a POST request to:
POST /services/data/v{api_version}/chatter/feed-elements
and creates a FeedItem linked to the record.
Updating a Message
If you need to edit a feed message (your own post), you can use update():
$opportunity->chatter()->update('0D5xx00000ABCDe', 'Updated deal size to £250k.');
This sends a PATCH request to:
PATCH /services/data/v{api_version}/chatter/feed-elements/{feedElementId}
and updates the feed item’s body content.
Commenting on a Message
To add a comment to an existing feed item, use comment():
$opportunity->chatter()->comment('0D5xx00000ABCDe', 'Agreed — let’s go for it.');
This issues a POST request to:
POST /services/data/v{api_version}/chatter/feed-elements/{feedElementId}/capabilities/comments/items
and appends a new FeedComment to the specified post.
### Example Workflow
$opportunity = Opportunity::find('0068d00000ABC123'); // Post a message $post = $opportunity->chatter()->post('Initial quote sent to client.'); // Add a follow-up comment $opportunity->chatter()->comment($post['id'], 'Client requested updated pricing.'); // Retrieve all feed items $feed = $opportunity->chatter()->all();
Notes
Feed actions are available for any Salesforce record with an associated Chatter feed (FeedEnabled objects). Returned data is normalized through SalesforceChatterResponse, so you can iterate and inspect feed elements easily. Posting and commenting automatically handle message segment formatting — plain text is supported by default, but future versions will support rich mentions, links, and file attachments.
flinty916/laravel-salesforce 适用场景与选型建议
flinty916/laravel-salesforce 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 9, 最近一次更新时间为 2025 年 08 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「php」 「github」 「command」 「service」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flinty916/laravel-salesforce 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flinty916/laravel-salesforce 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flinty916/laravel-salesforce 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Handles basic OAuth/OAuth2 authentication along with classes for common services
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
GitHub Webhook Listener with plugin-based API for creating your own triggerered actions
Creates a markdown changelog for your GitHub repository.
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-12