PHPackages                             faisalrizal/architect - 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. faisalrizal/architect

ActiveLibrary

faisalrizal/architect
=====================

1.0.2(8y ago)0371MITPHP

Since Aug 22Pushed 8y ago1 watchersCompare

[ Source](https://github.com/faisalrizal/architect)[ Packagist](https://packagist.org/packages/faisalrizal/architect)[ RSS](/packages/faisalrizal-architect/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (7)Used By (1)

Architect
=========

[](#architect)

[![Latest Version](https://camo.githubusercontent.com/492bdb25fbfc85ae0f312ad3200453afff346a8f58c185fcb450705aedc11e64/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f66616973616c72697a616c2f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://github.com/faisalrizal/architect/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/1cd02d7ce46852b26bef7f0b54cb1d07130e5229db7a48c60059e3d84b27c16b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f66616973616c72697a616c2f6172636869746563742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/faisalrizal/architect)[![Coverage Status](https://camo.githubusercontent.com/89974a2e3e367357925befddff3b73e49a31d8cfb475c71643ce16bac7f5db2a/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f66616973616c72697a616c2f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/faisalrizal/architect)[![Total Downloads](https://camo.githubusercontent.com/afecc4170eb50ba99c1254fcc4436d985fc5cebb136f07d1be69aa6f4721786b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66616973616c72697a616c2f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/faisalrizal/architect)

Introduction
------------

[](#introduction)

Architect is used for dynamically creating new structures for API resource relationships. Sounds confusing and pretentious?

Imagine you have a resource `Book` with a related resource `Author`.

```
Book 1-----n Author

```

### Normal embedded mode

[](#normal-embedded-mode)

This is how related resources are loaded by default using embedded mode.

```
{
   "books":[
      {
         "id":1,
         "author_id":1,
         "title":"How to save the world from evil",
         "pages":100,
         "author":{
            "id":1,
            "name":"Optimus Prime"
         }
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":{
            "id":2,
            "name":"Megatron"
         }
      }
   ]
}
```

With Architect now you can load related resources using `ids` mode and `sideloading` mode

### Ids mode

[](#ids-mode)

Only load the IDs of the related resource. [Using the primary key property of Eloquent models is in the roadmap.](https://github.com/esbenp/architect/issues/1)

```
{
   "books":[
      {
         "id":1,
         "author_id":1,
         "title":"How to save the world from evil",
         "pages":100,
         "author":1
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":2
      }
   ]
}
```

### Sideloading mode

[](#sideloading-mode)

Hoist the related resources into the global scope and leave behind the IDs using the ID mode resolver.

```
{
   "author":[
      {
         "id":1,
         "name":"Optimus Prime"
      },
      {
         "id":2,
         "name":"Megatron"
      }
   ],
   "books":[
      {
         "id":1,
         "author_id":1,
         "title":"How to save the world from evil",
         "pages":100,
         "author":1
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":2
      }
   ]
}
```

Usage
-----

[](#usage)

Architect works with normal array's (collections and resources), `Illuminate\Support\Collection`and `Illuminate\Database\Eloquent\Model`.

```
