2017 © Pedro Peláez
 

library laravel-clusterpoint

image

clusterpoint/laravel-clusterpoint

  • Friday, October 21, 2016
  • by normunds@clusterpoint.com
  • Repository
  • 7 Watchers
  • 2 Stars
  • 1,348 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Clusterpoint 4.x PHP Client API - Laravel Package

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Official Documentation

Documentation for the API can be found on the Clusterpoint website., (*2)

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

, (*3)

Client Usage Example

Here you can see standart Laravel Controller that uses our service., (*4)

<?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;
    }
}

, (*5)

Model Usage Example

First create your model in app folder:, (*6)

<?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., (*7)

<?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'));
    }
}

, (*8)

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:, (*9)

<?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., (*10)

<?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'));
    }
}

, (*11)

Multiple connections Example

You can set multiple connections and use what you needed in the Model., (*12)

First add a connection setting array in the main config file config/clusterpoint.php. For example a connection named "test", (*13)

<?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., (*14)

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:, (*15)

<?php

namespace App;

use Clusterpoint\Model;

class Example extends Model
{
    protected $connection = "test";
}

, (*16)

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

, (*17)

License

Clusterpoint 4.0 PHP Client API - Laravel Package is open-sourced software licensed under the MIT license, (*18)

The Versions

21/10 2016

dev-master

9999999-dev https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql

21/10 2016

4.0.6

4.0.6.0 https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql

03/05 2016

4.0.5

4.0.5.0 https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql

03/05 2016

4.0.4

4.0.4.0 https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql

15/04 2016

4.0.3

4.0.3.0 https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql

15/03 2016

4.0.2

4.0.2.0 https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql

19/02 2016

4.0.1

4.0.1.0 https://www.clusterpoint.com/

  Sources   Download

MIT

The Requires

 

by Clusterpoint
by Marks Gerasimovs

database laravel api php nosql clusterpoint jssql