PHPackages                             amirsarfar/dyna-base - 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. [API Development](/categories/api)
4. /
5. amirsarfar/dyna-base

AbandonedArchivedLibrary[API Development](/categories/api)

amirsarfar/dyna-base
====================

A headless CMS designed to create dynamically defined data models and API endpoints

24PHP

Since Sep 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/amirsarfar/dyna-base)[ Packagist](https://packagist.org/packages/amirsarfar/dyna-base)[ RSS](/packages/amirsarfar-dyna-base/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

 [![](https://camo.githubusercontent.com/a47b25bc613ac58bee4c0c7b64db44adf7d061fe0d34770c92561eeed3edf0f5/687474703a2f2f616d6972736172666172617a692e69722f696d616765732f44796e612d4769746875622d42616e6e65722d322e706e67)](https://camo.githubusercontent.com/a47b25bc613ac58bee4c0c7b64db44adf7d061fe0d34770c92561eeed3edf0f5/687474703a2f2f616d6972736172666172617a692e69722f696d616765732f44796e612d4769746875622d42616e6e65722d322e706e67)

About Dyna
----------

[](#about-dyna)

The idea behind Dyna is to offer dynamic-API-creation APIs. This means that you can build APIs from your front-end application by sending requests to certain APIs.

You just need to install this package in your Laravel application and run its migrations !

Database Schema
---------------

[](#database-schema)

 [![](https://camo.githubusercontent.com/fd04d667c57bf01dcefa59b79d3cab0aaa34b19009dad8c44161b718132475e5/687474703a2f2f616d6972736172666172617a692e69722f696d616765732f64617461626173652d736368656d612e706e67)](https://camo.githubusercontent.com/fd04d667c57bf01dcefa59b79d3cab0aaa34b19009dad8c44161b718132475e5/687474703a2f2f616d6972736172666172617a692e69722f696d616765732f64617461626173652d736368656d612e706e67)

The goal here is to get rid of database migrations and relations. To achive that we came with an idea that was to define models (former migrations) with a JSON object.

There are 5 main tables in this project: Types, Posts, Relations, Metas and LargeMetas.

Types table is responsible for holding definition (same as migrations) of post types. It has a unique key, a tilte and a JSON definition column.

Posts table holds an id and a type\_id that defines which post it is and of which type it is.

Metas table has an id, a post\_id, a key and a value that defines which post it belongs to, which attribute of the post it is (key) and what its value is.

LargeMetas table is the same as Metas table but its value column is longText instead of text to hold bigger data chunks.

Relations table has a parent\_key, child\_key, parent\_id, child\_id that defines which post/posts has/have which post/posts as parent/child and which attribute of the post it belongs to (keys).

Recommended Approach
--------------------

[](#recommended-approach)

### Create your post types

[](#create-your-post-types)

You should send a POST request to `/api/dyna/v1/types` in order to create a type. This end-point gets three parameters :

- key : It is a unique string that is used to refrence the type.
- title : It is a string.
- definition : It is a JSON array of type's attributes. Each attribute is a JSON object.

### Type's definition

[](#types-definition)

Each attribute has at least two key-value pairs: `name` and `type`.
The value of the `name` key is refrenced as attribute of posts of this type.
The value of the `type` key determines what kind of data is stored for this attribute.
Each attribute can also take an optional key that is `options`, the `options` key has an object value that describes the attribute's extended behavior. There are some examples of `definition` objects for different types below.

Supported attribute types:

- text

```
{
    "name" : "",
    "type" : "text",
    "options" :
    {
        // TODO ....
    }
}
```

- relation

```
{
    "name" : "",
    "type" : "relation",
    "options" :
    {
        "type_id" : "",
        "type_key" : "
