PHP code example of ytake / laravel-couchbase

1. Go to this page and download the library: Download ytake/laravel-couchbase 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/ */

    

ytake / laravel-couchbase example snippets


'providers' => [
    // added service provider
    \Ytake\LaravelCouchbase\CouchbaseServiceProvider::class,
    \Ytake\LaravelCouchbase\ConsoleServiceProvider::class,
]


'couchbase' => [
    'driver' => 'couchbase',
    'host' => 'couchbase://127.0.0.1',
    'user' => 'userName', // optional administrator
    'password' => 'password', // optional administrator
    // optional configuration / management operations against a bucket.
    'administrator' => [
        'user'     => 'Administrator',
        'password' => 'password',
    ],
],


'couchbase' => [
    'driver' => 'couchbase',
    'host' => 'couchbase://127.0.0.1,192.168.1.2',
    'user' => 'userName', // optional administrator
    'password' => 'password', // optional administrator
],

// service container access
$this->app['db']->connection('couchbase')
    ->table('testing')->where('whereKey', 'value')->first();

// use DB facades
\DB::connection('couchbase')
    ->table('testing')->where('whereKey', 'value')->get();

$value = [
    'click' => 'to edit',
    'content' => 'testing'
];
$key = 'insert:and:delete';

$result = \DB::connection('couchbase')
    ->table('testing')->key($key)->insert($value);

\DB::connection('couchbase')
    ->table('testing')->key($key)->upsert([
        'click'   => 'to edit',
        'content' => 'testing for upsert',
    ]);

\DB::connection('couchbase')
    ->table('testing')->key($key)->where('clicking', 'to edit')->delete();

\DB::connection('couchbase')
    ->table('testing')->key($key)
    ->where('click', 'to edit')->update(
        ['click' => 'testing edit']
    );

"delete from testing USE KEYS "delete" RETURNING *"
"update testing USE KEYS "insert" set click = ? where click = ? RETURNING *"

\DB::connection('couchbase')
    ->table('testing')
    ->where('id', 1)
    ->offset($from)->limit($perPage)
    ->orderBy('created_at', $sort)
    ->returning(['id', 'name'])->get();

$view = \DB::view("testing");
$result = $view->execute($view->from("dev_testing", "testing"));

'couchbase' => [
   'driver' => 'couchbase',
   'bucket' => 'session'
],

'couchbase-memcached' => [
    'driver'  => 'couchbase-memcached',
    'servers' => [
        [
            'host' => '127.0.0.1',
            'port' => 11255,
            'weight' => 100,
            'bucket' => 'memcached-bucket-name',
            'option' => [
                // curl option
            ],
        ],
    ],
],

'couchbase' => [
   'driver' => 'couchbase',
   'bucket' => 'session',
   'bucket_password' => 'your bucket password'
],


$this->app['db']->connection('couchbase')
    ->consistency(\CouchbaseN1qlQuery::REQUEST_PLUS)
    ->table('testing')
    ->where('id', 1)
    ->returning(['id', 'name'])->get();

$this->app['db']->connection('couchbase')
    ->callableConsistency(\CouchbaseN1qlQuery::REQUEST_PLUS, function ($con) {
        return $con->table('testing')->where('id', 1)->returning(['id', 'name'])->get();           
    });

use Ytake\LaravelCouchbase\Schema\Blueprint as CouchbaseBlueprint;

\Schema::create('samples', function (CouchbaseBlueprint $table) {
    $table->primaryIndex(); // primary index
    $table->index(['message', 'identifier'], 'sample_secondary_index'); // secondary index
    // dropped
    $table->dropIndex('sample_secondary_index'); 
    $table->dropPrimary();
});

return [
    'design' => [
        'Your Design Document Name' => [
            'views' => [
                'Your View Name' => [
                    'map' => file_get_contents(__DIR__ . '/../resources/sample.ddoc'),
                ],
            ],
        ],
    ]
];


    'connections' => [
        'couchbase' => [
            'driver' => 'couchbase',
            'bucket' => 'jobs',
            'queue' => 'default',
            'retry_after' => 90,
        ],
    ],
bash
php artisan queue:work couchbase --queue=send_email
 php
$cluster = new CouchbaseCluster('couchbase://127.0.0.1');
$clusterManager = $cluster->manager('Administrator', 'password');
$clusterManager->createBucket('testing', ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]);
$clusterManager->createBucket('memcache-couch', ['bucketType' => 'memcached', 'saslPassword' => '', 'flushEnabled' => true]);
sleep(5);
$bucketManager = $cluster->openBucket('testing')->manager();
$bucketManager->createN1qlPrimaryIndex();