1. Go to this page and download the library: Download mpociot/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/ */
use Mpociot\Couchbase\Eloquent\Model as Eloquent;
class User extends Eloquent {
public function items()
{
return $this->hasMany('Item');
}
}
use Mpociot\Couchbase\Eloquent\Model as Eloquent;
class Item extends Eloquent {
public function user()
{
return $this->belongsTo('User');
}
}
use Mpociot\Couchbase\Eloquent\Model as Eloquent;
class User extends Eloquent {
public function groups()
{
return $this->belongsToMany('Group', null, 'user_ids', 'group_ids');
}
}
use Mpociot\Couchbase\Eloquent\Model as Eloquent;
class User extends Eloquent {
public function books()
{
return $this->embedsMany('Book');
}
}
$books = User::first()->books;
$user = $book->user;
$book = new Book(['title' => 'A Game of Thrones']);
$user = User::first();
$book = $user->books()->save($book);
// or
$book = $user->books()->create(['title' => 'A Game of Thrones'])
$book = $user->books()->first();
$book->title = 'A Game of Thrones';
$book->save();
$book = $user->books()->first();
$book->delete();
// or
$user->books()->destroy($book);
$user->books()->associate($book);
$user->save();
return $this->embedsMany('Book', 'local_key');
use Mpociot\Couchbase\Eloquent\Model as Eloquent;
class Book extends Eloquent {
public function author()
{
return $this->embedsOne('Author');
}
}
$newAuthor = new Author(['name' => 'Jane Doe']);
$book->author()->save($newAuthor);
use Mpociot\Couchbase\Eloquent\HybridRelations;
class User extends Eloquent {
use HybridRelations;
protected $connection = 'mysql';
public function messages()
{
return $this->hasMany('Message');
}
}
use Mpociot\Couchbase\Eloquent\Model as Eloquent;
class Message extends Eloquent {
protected $connection = 'couchbase';
public function user()
{
return $this->belongsTo('User');
}
}
$users = User::remember(10)->get();
DB::connection()->disableQueryLog();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.