糖CRM / laravel-bean
SugarCRM eloquent风格连接器,用于Laravel框架。
此包尚未发布版本,信息有限。
README
SugarCRM Bean基础设施,用于Laravel
使用此工具,可以轻松从Laravel应用程序访问SugarCRM beans
此包目前处于alpha状态,不适合生产使用
待办事项
更新Guzzle到最新版本(5.*)
实现关系
实现缺失的过滤器
测试
以下是一些基本说明,帮助您开始使用此包。
安装
此包旨在通过Composer安装。以下说明假设您已安装并配置了Composer。
配置
您已安装laravel-bean后,需要对其进行配置,以便它可以使用。
生产配置
Laravel-bean通过API与SugarCRM通信,而不是通过直接数据库连接。
元数据缓存
为了您的方便,我们本地存储元数据,因此您需要将新表添加到系统中。
php artisan migrate --package sugarcrm/laravel-bean
用法
Laravel的查询构建器位于Laravel-Bean的根部,因此它的大部分功能和原则都符合该包。
Beans
截至本文撰写时,Laravel-Bean尚未设置为用作真正的查询构建器。您必须设置扩展Laravel-Bean的模型,才能使用查询构建器。
SugarCRM用户模型将类似于以下内容
<?php namespace App\Models\Beans;
use Sugarcrm\Bean\Bean;
class UserBean extends Bean {
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'Users';
}
查询
Laravel-Bean的最终目标是尽可能地将SugarCRM的过滤器和关系API与原生Laravel Eloquent结合。
选择
根据我们的UserBean示例,我们可以查询用户模块
$bean = new UserBean();
$beans = $bean->get(); // get all records in the module. Please keep in mind that hardcoded limit is 1000 records.
您可以设置限制和偏移量
$beans = $bean->take(10)->get(); // get first 10 records in the module
$beans = $bean->take(10)->skip(10)->get(); // get skip first 10 records and get next 10 records in the module
Where子句
由于SugarCRM API的性质,并非所有典型数据库操作都可用。
以下是一个操作类型列表
$equals在该字段上进行精确匹配。
$bean->where('name', 'something')->get();
$not_equals匹配非匹配值。
$bean->where('name', '!=', 'something')->get();
$starts匹配以该值开头的任何内容。
$bean->whereStartsWith('name', 'something')->get();
或
$bean->where('name', 'starts', 'something')->get();
$ends匹配以该值结尾的任何内容。
$bean->whereEndsWith('name', 'something')->get();
或
$bean->where('name', 'ends', 'something')->get();
$contains匹配包含该值的任何内容。
$bean->where('name', 'like', 'something')->get();
$in查找字段匹配数组中指定值之一的任何内容。
$bean->whereIn('name', array('Something','Else'))->get();
$not_in查找字段与指定的数组值不匹配的所有内容。
$bean->whereNotIn('name', array('Something','Else'))->get();
$is_null检查字段是否为null。此操作不需要指定值。
$bean->whereNull('name')->get();
$not_null检查字段是否不为null。此操作不需要指定值。
$bean->whereNotNull('name')->get();
$lt当字段值小于指定值时匹配。
$bean->where('count', '<', 1)->get();
$lte当字段值小于或等于指定值时匹配。
$bean->where('count', '<=', 1)->get();
$gt当字段值大于指定值时匹配。
$bean->where('count', '>', 1)->get();
$gte当字段值大于或等于指定值时匹配。
$bean->where('count', '>=', 1)->get();