1. Go to this page and download the library: Download pravodev/laravel-couchdb 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 Robsonvn\CouchDB\Eloquent\Model as Eloquent;
class User extends Eloquent {
protected $dates = ['birthday'];
}
$users = User::where('birthday', '>', new DateTime('-18 years'))->get();
use Robsonvn\CouchDB\Eloquent\Model as Eloquent;
class User extends Eloquent {
public function items()
{
return $this->hasMany('Item');
}
}
use Robsonvn\CouchDB\Eloquent\Model as Eloquent;
class Item extends Eloquent {
public function user()
{
return $this->belongsTo('User');
}
}
use Robsonvn\CouchDB\Eloquent\Model as Eloquent;
class User extends Eloquent {
public function groups()
{
return $this->belongsToMany('Group', null, 'user_ids', 'group_ids');
}
}
use Robsonvn\CouchDB\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 Robsonvn\CouchDB\Eloquent\Model as Eloquent;
class Book extends Eloquent {
public function author()
{
return $this->embedsOne('Author');
}
}