PHP code example of clusterpoint / laravel-clusterpoint
1. Go to this page and download the library: Download clusterpoint/laravel-clusterpoint library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
clusterpoint / laravel-clusterpoint example snippets
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;
}
}
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
}
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'));
}
}