PHPackages                             hidejec/liquido-orm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. hidejec/liquido-orm

ActiveLibrary[Framework](/categories/framework)

hidejec/liquido-orm
===================

LiquidoORM Framework Developed by Team Liquido(Inspired by Laravel Eloquent ORM)

0.0.2(10y ago)7241PHPPHP &gt;=5.3.0

Since Apr 29Pushed 9y ago4 watchersCompare

[ Source](https://github.com/Hidejec/LiquidoORM)[ Packagist](https://packagist.org/packages/hidejec/liquido-orm)[ Docs](https://github.com/Hidejec/Liquido)[ RSS](/packages/hidejec-liquido-orm/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

LiquidoORM
==========

[](#liquidoorm)

LiquidoORM is a simple object relational mapping which helps you query database easily with just a minimum amount of code.

How to Install
--------------

[](#how-to-install)

```
composer require hidejec/liquido-orm "0.0.2"
```

then autoload in your project

```
require 'vendor/autoload.php';
```

Configuration
-------------

[](#configuration)

Create a configuration file for your database and name it **dbconfig.liquido.php**

```
# File name: dbconfig.liquido.php

```

And save it inside your project root directory.

Intialize the LiquidoORM in your index.php

```
  new Liquido\App;
```

Usage
-----

[](#usage)

Create a model and extend the LiquidoORM. For example a Customer Model

```
  #File: app/Model/Customer.php

  namespace Model;

  use Liquido\Model\LiquidoORM; #Requirement!

  class Customer extends LiquidoORM{ #Requirement!
  }
```

The Model automatically set the table with the plural name of the Model so you don't have to write again and again the table you want to run the query.

> In our example, The table is set to `customers`. So be sure that you have a table named `customers` inside your database. Another example: if you have a model class name `Product`, the table will be set to `products` automatically. Another example: Class Name `Illness` = `illnesses`.

If you want to specify custom table name, just add this inside your model:

```
protected static $table = "tablename";
```

##### Note that it should be `protected static $table`

[](#note-that-it-should-be-protected-static-table)

**Get all result and store it in a variable**

```
 $list = Customer::all();
```

Simple right ? :) It returns an array of results which you can manipulate inside a loop.

###### Example if you are using a twig view

[](#example-if-you-are-using-a-twig-view)

```
{% for customer in list %}
	{{ customer.Email|e }}
	#or
	{{ customer["Email"] }}
{% endfor %}
```

**Get a single result passing a primary key ID**

```
  $customer = Customer::withId(1);

  echo $customer["Username"]; # Prints the username of the customer
```

**Get result with predefined conditions**

###### Example I will fetch all data with the first name "Jacob". To do this...

[](#example-i-will-fetch-all-data-with-the-first-name-jacob-to-do-this)

```
  $list = Customer::with([
			      'First_Name' => 'Jacob'
			    ]);
```

###### Fetching with multiple conditions

[](#fetching-with-multiple-conditions)

```
$list = Customer::with([
      			'Status'=> 'Single',
      			'First_Name' => 'Jacob',
      			'condition-type'=> 'AND'
			  ]);
```

> This will going to select all rows with a Status "Single" AND First\_Name "Jacob".

***condition-type*** can be a

- AND
- &amp;&amp;
- OR
- ||

How about an OR inside a condition-type AND.

**Example *Select all rows with a Status "Single" AND First\_Name "Jacob" AND (Last\_Name "Ramos" OR "Reyes")* To do this...**

```
  $list = Customer::with([
        			'Status'=> 'Single',
        			'First_Name' => 'Jacob',
        			'Last_Name' => ['Ramos', 'Reyes'],
        			'condition-type'=> 'AND'
    			]);
```

The ` 'Last_Name' => ['Ramos', 'Reyes']` Automatically pertains to the conditional statement "OR". So in normal query it will be **WHERE Last\_Name = 'Ramos' OR Last\_Name = 'Reyes';**

I prefer the above method if your going the search for a data with a specified string. But what if your going to fetch the data with the id's less than 10.

**Get data for numerical conditions**

> Note that you can also use this similar to the above ***::with()*** but I prefer to use the liquid method ***::where()*** if you have a condition related to numbers since it's much easy to use.

```
$list = Customer::where("id", "
