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

ActiveLibrary

phuongtt/architect
==================

1.0.2(6y ago)03.7k↓39.4%1MITPHP

Since Aug 22Pushed 6y agoCompare

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

READMEChangelog (1)Dependencies (5)Versions (7)Used By (1)

Architect
=========

[](#architect)

[![Latest Version](https://camo.githubusercontent.com/bd8d5fd70c18c456987f3dc94f006138cb390c2ecc5a9c59322358efa9626e33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f657362656e702f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://github.com/esbenp/architect/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/b54857762cfc96b1dcb21ecb26d960d3f0c232c628bfac44400d50e624c445ba/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f657362656e702f6172636869746563742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/esbenp/architect)[![Coverage Status](https://camo.githubusercontent.com/8e1be7c3c571e8762c6ad704cea7a1b456048c7318e9df856a806abe05e0f568/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f657362656e702f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/esbenp/architect)[![Total Downloads](https://camo.githubusercontent.com/d0b86485edc58b6ce02d1e982749f2da16c18bc2cf859698539782fa68f88811/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f7074696d75732f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/optimus/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`.

```
