承接 clusterpoint/laravel-clusterpoint 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clusterpoint/laravel-clusterpoint

Composer 安装命令:

composer require clusterpoint/laravel-clusterpoint

包简介

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Official Documentation

Documentation for the API can be found on the Clusterpoint website.

Install

  1. Install the package.
    composer require clusterpoint/laravel-clusterpoint
  2. Register Service Provider in your config/app.php file.
    Clusterpoint\ClusterpointServiceProvider::class
  3. Publish config file.
    php artisan vendor:publish --provider="Clusterpoint\ClusterpointServiceProvider"
  4. 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

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 clusterpoint/laravel-clusterpoint 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 5
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-19