PHP code example of ametsuramet / simple_orm

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

    

ametsuramet / simple_orm example snippets


'providers' => [
    // ...
    Amet\SimpleORM\ModelBuilderServiceProvider::class,
],

$app->register(Amet\SimpleORM\ModelBuilderServiceProvider::class);

// ...

use App\ORM\Project;

class yourController extends Controller {
	
	public function yourMethod()
	{
		$projects = new Project;
		$projects = $projects->get();

		dd($projects);
	}
// ...


// ...
		$projects = (new Project)->get();
		dd($projects);
// ...


...
class Project extends BaseQuery
{
	protected $table = 'projects';
...

...
class Project extends BaseQuery
{
	protected $default_key = 'uuid';
...

// ...
		$projects = new Project;
		$projects = $projects->where(['id',1])->get();
		dd($projects);
// ...


// ...
		$wheres = [
			['id','>=',10], 
			['date','>=','2017-01-01'], 
		];
		$projects = new Project;
		$projects = $projects->where($wheres)->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->limit(10)->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->limit(20,10)->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->deleted_only()->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->deleted(true)->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->info();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->orderBy('id')->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->orderBy('id','desc')->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->groupBy('id')->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->groupBy(['id','date'])->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->insert(["name" => 'new project']);
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->update(29,["name" => 'new project']);
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->delete(29);
// ...


// ...
		$projects = new Project;
		$projects = $projects->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->first();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->find(29);
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->last();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->paginate($params);
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->set_show_column(['id','first_name','last_name'])->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->hide_relation()->get();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->count();
		dd($projects);
// ...


// ...
		$projects = new Project;
		$projects = $projects->getQueryLog();
		dd($projects);
// ...


...
class Project extends BaseQuery
{
	public function user()
	{
		$this->hasOne(User:class,'id','user_id','user');
	}
...

...
class Project extends BaseQuery
{
	public function user()
	{
		$this->hasOne(User:class,'id','user_id','user',['id','first_name','last_name']);
	}
...

...
class Project extends BaseQuery
{
	public function user()
	{
		$this->hasOne(User:class,'id','user_id','user');
	}
...

...
class Project extends BaseQuery
{
	public function user()
	{
		$this->hasOne(User:class,'id','user_id','user',['id','first_name','last_name']);
	}
...

...
class Project extends BaseQuery
{
	public function user()
	{
		$pivot_table = [UserProject::class,'user_id','company_id'];
		$this->manyToMany(User:class,'id','user_id','user',$pivot_table);
	}
...

...
class Project extends BaseQuery
{
	public function user()
	{
		$pivot_table = [UserProject::class,'user_id','company_id'];
		$this->manyToMany(User:class,'id','user_id','user',$pivot_table,['id','first_name','last_name']);
	}
...
bash
php artisan simple_orm:model Project
bash
php artisan simple_orm:interactive