PHPackages                             phitech/entities - 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. [Database &amp; ORM](/categories/database)
4. /
5. phitech/entities

AbandonedLibrary[Database &amp; ORM](/categories/database)

phitech/entities
================

Provides methods for managing entities that consist two database tables: main and meta. It allows for an indiscrete set of attributes by storing them as key-value sets in the meta table, while the most important attributes and indexes are in the main table. This structure is inspired by the post/postmeta structure in Wordpress databases.

046PHP

Since Nov 2Pushed 3y agoCompare

[ Source](https://github.com/phitech-consulting/Entities)[ Packagist](https://packagist.org/packages/phitech/entities)[ RSS](/packages/phitech-entities/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Phitech Entities Library
========================

[](#phitech-entities-library)

Author: Phitech Consulting
Package name: phitech/entities

Description: Provides methods for managing entities that consist two database tables: main and meta. It allows for an indiscrete set of attributes by storing them as key-value sets in the meta table, while the most important attributes and indexes are in the main table. This structure is inspired by the post/postmeta structure in Wordpress databases.

Important: This package requires MySQL DBMS. MariaDB won't do. The reason: 👇

*"All databases except SQL Server require the columns in the second argument of the upsert method to have a "primary" or "unique" index. In addition, the MySQL database driver ignores the second argument of the upsert method and always uses the "primary" and "unique" indexes of the table to detect existing records."* See also: .

Installation
------------

[](#installation)

This library is installed using composer.

```
$ composer require phitech/entities

```

```
$ composer install

```

```
$ php artisan migrate

```

Usage
-----

[](#usage)

To test if everything is installed correctly in your Laravel application, run:

```
$ php artisan entities:test

```

Create a new entity:

```
$ php artisan entities:make

```

For instance 'order':

```
$ php artisan entities:make order orders

```

An entity definition will now automatically be placed in the entities table which looks like:

```
{
"entity_name":"order",
"main_db_table":"orders",
"meta_db_table":"orders_meta",
"meta_instance_id_column":"order_id",
"main_required_columns":["order_id"]
}

```

You should now make two tables by using database migrations. You must do this manually, because this application is not able to do this for you. Examples of the two database migration scripts are added below.

### Main table

[](#main-table)

```
$ php artisan migrate create_orders_table

```

Paste this script below into the newly created migration script. Edit the table name (here: *orders*). Add table attributes to your own preference and using the guidelines as described below.

```
