PHP code example of guifcoelho / immu-table

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

    

guifcoelho / immu-table example snippets


use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $table = "table_example";
}

use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $fields = ['id', 'name', 'email'];
}

use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $hidden = ['this', 'that'];
}

use guifcoelho\ImmuTable\Model;

class Sample extends Model
{
    protected $primary_key = 'not_id';
}

$query = SampleModel::where('id', 10)->first();

$query = SampleModel::where('price', '>', 50)->first();

$query = SampleModel::where('price', '>', 50)->where('id', '<=', 10)->get();

$query = SampleModel::where('price', '>', 50)
            ->where('id', '<=', 10)
            ->orWhere('price', '<', 10)
            ->get();

use guifcoelho\ImmuTable\Model;

use Sample2;
use Sample3;
use Sample4;
use Sample5;

class Sample1 extends Model
{
    protected $table = "table_example";

    public function owner(){
        return $this->ImmuTable_belongsTo(Sample2::class [, $field, $field_in_parent_class]);
    }

    public function parents(){
        return $this->ImmuTable_belongsToMany(Sample3::class [, $pivot_table, $field_in_pivot, $parent_field_in_pivot, $field, $field_in_parent])
    }

    public function child(){
        return $this->ImmuTable_hasOne(Sample4::class [, $field_in_child_model, $field]);
    }

    public function children(){
        return $this->ImmuTable_hasMany(Sample5::class [, $field_in_child_models, $field]);
    }
}