PHPackages                             somnambulist/attribute-model - 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. somnambulist/attribute-model

ActiveLibrary

somnambulist/attribute-model
============================

Provides a base model that uses an internal array of attributes with type casting

3.1.0(2y ago)04.0k↑14.3%2MITPHPPHP &gt;=8.1

Since Sep 7Pushed 1y ago3 watchersCompare

[ Source](https://github.com/somnambulist-tech/attribute-model)[ Packagist](https://packagist.org/packages/somnambulist/attribute-model)[ RSS](/packages/somnambulist-attribute-model/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (13)Used By (2)

Attribute Model
===============

[](#attribute-model)

[![GitHub Actions Build Status](https://camo.githubusercontent.com/327af6b25612b48f617dabfc5fb081fb8e07764e09c9459486521cc91eba775d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f6d6e616d62756c6973742d746563682f6174747269627574652d6d6f64656c2f74657374732e796d6c3f6c6f676f3d676974687562266272616e63683d6d61696e)](https://github.com/somnambulist-tech/attribute-model/actions?query=workflow%3Atests)[![Issues](https://camo.githubusercontent.com/31d5c12008fd2983d21ca45b5fafdacd117bbb9659143abd88ec79e1a04b6e70/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736f6d6e616d62756c6973742d746563682f6174747269627574652d6d6f64656c3f6c6f676f3d676974687562)](https://github.com/somnambulist-tech/attribute-model/issues)[![License](https://camo.githubusercontent.com/a98743085f705bb74332df07a07ec7bb118a81f02fdcbc46d99abfee6e4a80b7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736f6d6e616d62756c6973742d746563682f6174747269627574652d6d6f64656c3f6c6f676f3d676974687562)](https://github.com/somnambulist-tech/attribute-model/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/d54c43761e786406e2d994a5311248c1756469c65c010c4392781edcceca2293/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6d6e616d62756c6973742f6174747269627574652d6d6f64656c3f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/somnambulist/attribute-model)[![Current Version](https://camo.githubusercontent.com/5b66220191c3c6cf4178decd2e3c177b67147dfd851ceb692c488187d1dd0e8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6d6e616d62756c6973742f6174747269627574652d6d6f64656c3f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/somnambulist/attribute-model)

A sort-of-kind-of ActiveModel type'ish base for Models that rely on an array of attributes. Includes a type-casting sub-system for casting attributes to values. Extracted from read-models.

The focus is for creating read-only Model representations for use in presentation layers. This library is used by [somnambulist/read-models](https://github.com/somnambulist-tech/read-models) and [api-client](https://github.com/somnambulist-tech/api-client).

Requirements
------------

[](#requirements)

- PHP 8.1+
- pragmarx/ia-str

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

[](#installation)

Install using composer, or checkout / pull the files from github.com.

- composer require somnambulist/attribute-model

Usage
-----

[](#usage)

Extend to a model e.g. User; or implement into a base model and add extra functionality. Use attribute casting if needed before passing attributes into the model.

```
