PHPackages                             rareloop/view-models - 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. rareloop/view-models

ActiveLibrary

rareloop/view-models
====================

A small package to make dealing with views easier

v1.0.1(8y ago)024MITPHPPHP ^7

Since Jul 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Rareloop/view-models)[ Packagist](https://packagist.org/packages/rareloop/view-models)[ Docs](https://github.com/Rareloop/view-models)[ RSS](/packages/rareloop-view-models/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

**This package is deprecated. View Models are now baked into the Lumberjack core.**

View Models
===========

[](#view-models)

Here, a `ViewModel` refers to something that takes data and transforms it into the correct format for a specific view. They are **input-output machines**.

For example, for this `twig` view:

```
{% for link in links %}
    {{ link.title }}
{% endfor %}
```

You will need to construct an array that looks like this (e.g. in your controller):

```
// Get pages from the database somehow
$pages = Page::all();

$data = ['links' => []];

foreach ($pages as $page) {
    // Map the page to the correct structure for the view
    $data['links'][] = [
        'url' => $page->permalink,
        'title' => $page->post_title,
    ];
}
```

\*\* ViewModels abstract away that transformation. This means you don't have to duplicate that transformation logic across multiple controllers, making your code eaiser to change.\*\*

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: 12 Basepoint, Andersons Road, Southampton, Hampshire, SO14 5FE.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require rareloop/view-models
```

### View Model Usage

[](#view-model-usage)

They should always return an array. The easiest way to achieve this is to run your data through the `compose` method on the View Model.

They should **not** fetch data from anywhere (e.g. database). This is the job of a `ViewModelComposer`.

Using an example `ViewModel` (e.g. in a controller):

```
$params = new ParameterBag([
    'links' => [
        'https://google.com',
        'https://rareloop.com',
    ],
]);

$context['links'] = \App\ViewModels\Links::make($params);
```

Here is an example `ViewModel` implementation:

```
namespace App\ViewModels\Links;

use Rareloop\ViewModels\ParameterBag;
use Rareloop\ViewModels\ViewModel;

class Links extends ViewModel
{
    public static function make(ParameterBag $params): array
    {
        // Transform the data into the correct structure
        $data = array_map(function ($item) {
            return [
                'url' => $item['ID'],
            ];
        }, $params->links);

        // Make sure the data is an array
        return static::compose($data);
    }
}
```

### Introducing View Model Composers

[](#introducing-view-model-composers)

A `ViewModelComposer` is simply a wrapper around a `ViewModel`, but is only concerned how to get data ready for a `ViewModel`.

These should be used instead of duplicating logic when creating `ViewModel`s (e.g. in controllers).

Example `ViewModelComposer` implementation:

```
class RelatedLinks
{
    public static function make(): array
    {
        // e.g. you could get the data out of the database for the related links for this page
        $args = new ParameterBag([
            'links' => [
                'http://google.com',
                'https://rareloop.com',
            ],
        ]);

        return Links::make($args);
    }
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3228d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1554376?v=4)[Rareloop](/maintainers/rareloop)[@Rareloop](https://github.com/Rareloop)

---

Top Contributors

[![adamtomat](https://avatars.githubusercontent.com/u/2631499?v=4)](https://github.com/adamtomat "adamtomat (1 commits)")

---

Tags

rareloopview-models

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rareloop-view-models/health.svg)

```
[![Health](https://phpackages.com/badges/rareloop-view-models/health.svg)](https://phpackages.com/packages/rareloop-view-models)
```

###  Alternatives

[kitetail/zttp

A developer-experience focused HTTP client, optimized for most common use cases.

1.7k1.2M72](/packages/kitetail-zttp)[cpriego/valet-linux

A more enjoyable local development experience for Linux.

1.5k135.9k](/packages/cpriego-valet-linux)[rareloop/router

A powerful PHP Router for PSR7 messages inspired by the Laravel API

92178.9k4](/packages/rareloop-router)[freearhey/wikidata

A PHP client for working with Wikidata API.

5628.6k](/packages/freearhey-wikidata)[mvdnbrk/dhlparcel-php-api

DHL Parcel API client for PHP

3957.9k5](/packages/mvdnbrk-dhlparcel-php-api)[jofrysutanto/windsor

YAML-ised Configuration for ACF

549.2k](/packages/jofrysutanto-windsor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
