clusterpoint/laravel-clusterpoint
Composer 安装命令:
composer require clusterpoint/laravel-clusterpoint
包简介
README 文档
README
Official Documentation
Documentation for the API can be found on the Clusterpoint website.
Install
- Install the package.
composer require clusterpoint/laravel-clusterpoint - Register Service Provider in your
config/app.phpfile.
Clusterpoint\ClusterpointServiceProvider::class - Publish config file.
php artisan vendor:publish --provider="Clusterpoint\ClusterpointServiceProvider" - Edit config – The main config file path is
config/clusterpoint.php
however we recommend to add your credentials to your .env file in laravel project root directory.
CP_HOST=https://api-eu.clusterpoint.com/v4
CP_ID=42
CP_USERNAME=myusername@clusterpoint.com
CP_PASSWORD=mypassword
Usage examples
##Client Usage Example Here you can see standart Laravel Controller that uses our service.
<?php namespace App\Http\Controllers; use Clusterpoint\Client; // use our package. class ExampleController extends Controller { public function getIndex() { $cp = new Client(); // by defualt uses 'default' connection name from ./config/clusterpoint.php // Set the collection to work with to initalize the query builder for it. $collection = $cp->database("database.collection"); // Build your query $results = $collection->where('color', 'red') ->where('availability', true) ->limit(5) ->groupBy('category') ->orderBy('price') ->select(['name', 'color', 'price', 'category']) ->get(); // Access your results return $results[0]->price; } }
##Model Usage Example
First create your model in app folder:
<?php namespace App; use Clusterpoint\Model; class Example extends Model { protected $db = "database.collection"; // set your databse and collection names //protected $primaryKey = "custom_id"; // If you want to define specific specific primary key, default = _id }
Now you can use model inside the controller.
<?php namespace App\Http\Controllers; use App\Example; // use your model. class ExampleController extends Controller { public function getIndex() { $example = Example::where('price', '>', 200)->first(); $example->price = 300; $example->save(); return view('example', compact('example')); } }
##Route Model Binding Example
We will use model created above to show this example, first bind your model in app/Http/routes.php file like this:
<?php Route::model('example', 'App\Example'); Route::get('/examples/{example}', 'ExampleController@getIndex');
Now if you pass the primary key value in your url like myweb.dev/examples/42 you can access the document already inside your controller like this.
<?php namespace App\Http\Controllers; use App\Example; class ExampleController extends Controller { public function getIndex($example) { $id = $example->_id; // value is 42 $name = $example->name; $price = $example->price; return view('example', compact('name','price')); } }
##Multiple connections Example You can set multiple connections and use what you needed in the Model.
First add a connection setting array in the main config file config/clusterpoint.php.
For example a connection named "test"
<?php return array( "default" => array( 'host' => env('CP_HOST', 'https://api-eu.clusterpoint.com/v4'), 'account_id' => env('CP_ID', ''), 'username' => env('CP_USERNAME', ''), 'password' => env('CP_PASSWORD', ''), ), "test" => array( 'host' => env('CP1_HOST', 'https://api-eu.clusterpoint.com/v4'), 'account_id' => env('CP1_ID', ''), 'username' => env('CP1_USERNAME', ''), 'password' => env('CP1_PASSWORD', ''), ) );
However we recommend you to add your credentials to your .env file in the laravel project root directory.
CP1_HOST=https://api-eu.clusterpoint.com/v4
CP1_ID=42
CP1_USERNAME=myusername@clusterpoint.com
CP1_PASSWORD=mypassword
Now You can use the connection in Your Model:
<?php namespace App; use Clusterpoint\Model; class Example extends Model { protected $connection = "test"; }
Support, Feature Requests & Bug Reports
- GitHub issues for bug reports and feature requests
- StackOverflow to ask questions (please make sure to use the clusterpoint tag)
- You can also send an e-mail to our support team at support@clusterpoint.com
License
Clusterpoint 4.0 PHP Client API - Laravel Package is open-sourced software licensed under the MIT license
clusterpoint/laravel-clusterpoint 适用场景与选型建议
clusterpoint/laravel-clusterpoint 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.4k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nosql」 「database」 「php」 「api」 「laravel」 「clusterpoint」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 clusterpoint/laravel-clusterpoint 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 clusterpoint/laravel-clusterpoint 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 clusterpoint/laravel-clusterpoint 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
The DreamFactory(tm) CouchDB Service.
Store your language lines in the database, yaml or other sources
The CodeIgniter Redis package
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Symfony lock Tarantool store
统计信息
- 总下载量: 1.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-19