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

ActiveLibrary

iphuongtt/architect
===================

1.0.2(8y ago)1511MITPHP

Since Aug 22Pushed 8y ago1 watchersCompare

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

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

Architect
=========

[](#architect)

[![Latest Version](https://camo.githubusercontent.com/8eb0af47a4ba88f2708524d3312d53e2d28b5620c8fef40fc5a5ccad7028de0b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f697068756f6e6774742f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://github.com/iphuongtt/architect/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/837b119181c969a7dcfc83217644d36e3b18791dbca2a683321378bccd63f3d5/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f697068756f6e6774742f6172636869746563742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/iphuongtt/architect)[![Coverage Status](https://camo.githubusercontent.com/7161659adcefaedce98091785f2126ce77cb39c5e27a2ef2f600f6a2e3ad2745/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f697068756f6e6774742f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/iphuongtt/architect)[![Total Downloads](https://camo.githubusercontent.com/9579a181b75b2364ddbea64e3af220c5d238f69ab48d7f226297be5fc10bc011/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f697068756f6e6774742f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iphuongtt/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`.

```
