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

ActiveLibrary

bulwark/architect
=================

v1.0.2(8y ago)11211MITPHP

Since Dec 5Pushed 8y agoCompare

[ Source](https://github.com/bulwark1374/architect)[ Packagist](https://packagist.org/packages/bulwark/architect)[ RSS](/packages/bulwark-architect/feed)WikiDiscussions master Synced 3d ago

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

Architect
=========

[](#architect)

[![Latest Version](https://camo.githubusercontent.com/77c2e2dcd84c21f534adcddf519e51d39b33a8686aa538002b23129794e1cab0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62756c7761726b313337342f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://github.com/bulwark1374/architect/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/2128410b68b00f177fb7b4d9d21c74043807efb5ee1a04e9e0089e730fbf6111/68747470733a2f2f7472617669732d63692e6f72672f62756c7761726b313337342f6172636869746563742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bulwark1374/architect)[![Coverage Status](https://camo.githubusercontent.com/630866afb7e28fbb2be7b812aa2b5309d0ab73a00cc7cf6066e8eb18a8626ae2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62756c7761726b313337342f6172636869746563742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bulwark1374/architect)[![Total Downloads](https://camo.githubusercontent.com/541eb1d4449c7385249bf8e3c28c3642322bff0ca0530889c4c0c9160241928e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62756c7761726b2f6172636869746563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bulwark/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":"Linus torvalds"
         }
      },
      {
         "id":2,
         "author_id":2,
         "title":"How to take over the world",
         "pages":100,
         "author":{
            "id":2,
            "name":"Richard stallman"
         }
      }
   ]
}
```

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.

```
{
   "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":"Linus torvalds"
      },
      {
         "id":2,
         "name":"Richard stallman"
      }
   ],
   "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`.

```
