PHP code example of sinemah / coucheloquent

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

    

sinemah / coucheloquent example snippets




return [
    'session' => env('COUCHDB_SESSION', 300),
    'username' => env('COUCHDB_USER'),
    'password' => env('COUCHDB_PASSWORD'),
    'database' => env('COUCHDB_DATABASE', 'laravel'),
    'url' => env('COUCHDB_URL', 'http://couchdb:5984'),
];



namespace App\Models;

use Sinemah\CouchEloquent\Eloquent\Model;

class Item extends Model
{
    protected $casts = [
        'name' => 'json',
    ];
} 

use Ramsey\Uuid\Uuid;

$doc = Pet::create([
    'name' => [
        'first_name' => 'Chico',
        'last_name' => 'Mr.'
    ],
    'treatments' => [
        [
            'id' => Uuid::uuid6(),
            'random_int' => rand(0, 10),
        ]
    ],
    'gender' => 'male',
    'breed' => 'Mastin-Mix'
]); 

$pet = $pets->first();
$pet->name = [
    'first_name' => 'chico',
    'last_name' => 'MR.'
];

$pet->save();

 $pets = Pet::query()
    ->where('breed', 'Mastin-Mix')
    ->whereIn('breed', ['Mastin-Mix'])
    ->whereBetween('created_at.values.year', [2022, 2023])
    ->where(function(Builder $query) {
        $query->orWhere('gender', 'male');
        $query->orWhere('gender', 'female');

        return $query;
    })
    ->whereHas('treatments', function(Builder $query) {
        $query->where('random_int', 1);

        return $query;
    })
    ->get();