PHPackages                             cline/struct - 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. cline/struct

ActiveLibrary

cline/struct
============

Lean, attribute-driven Laravel data objects with explicit validation and Eloquent casting support

2.1.2(1mo ago)01.3k↓19.4%6MITPHPPHP ^8.5.0CI failing

Since Mar 8Pushed 1mo agoCompare

[ Source](https://github.com/faustbrian/struct)[ Packagist](https://packagist.org/packages/cline/struct)[ RSS](/packages/cline-struct/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (8)Dependencies (20)Versions (10)Used By (6)

[![GitHub Workflow Status](https://github.com/faustbrian/struct/actions/workflows/quality-assurance.yaml/badge.svg)](https://github.com/faustbrian/struct/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/1cd2794bb1913cf6edc188555a51cab886df6380918cc72548fb4b8ecac46626/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c696e652f7374727563742e737667)](https://packagist.org/packages/cline/struct)[![Software License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/522abfa83ddeb80f24cffe2b4ad0966ab09a5cfb79c3dd44b6e0350510dd301d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c696e652f7374727563742e737667)](https://packagist.org/packages/cline/struct)

---

struct
======

[](#struct)

Lean, attribute-driven Laravel data objects for applications that want the useful parts of `spatie/laravel-data` without the magic-heavy surface area.

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

[](#requirements)

> **Requires [PHP 8.4+](https://php.net/releases/)**

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

[](#installation)

```
composer require cline/struct
```

Optional features:

```
composer require cline/math
composer require cline/money
composer require cline/numerus
composer require cline/phone-number
composer require cline/postal-code
composer require ramsey/uuid
composer require cline/semver
```

Install `cline/math` when you want first-class arbitrary-precision `BigNumber`, `BigInteger`, `BigDecimal`, or `BigRational` DTO properties.

```
composer require cline/money
```

Install `cline/money` when you want first-class `Money`, `RationalMoney`, or `MoneyBag` DTO properties, or the `#[AsMoney(...)]` attribute for scalar currency amounts.

```
composer require cline/numerus
```

Install `cline/numerus` when you want first-class `Numerus` DTO properties or numeric normalization attributes such as `#[Round]`, `#[Clamp]`, and `#[Abs]`.

```
composer require cline/phone-number
```

Install `cline/phone-number` when you want first-class `PhoneNumber` DTO properties, including scalar local-number hydration with `#[AsPhoneNumber(regionCode: ...)]`.

```
composer require cline/postal-code
```

Install `cline/postal-code` when you want first-class `PostalCode` DTO properties, including scalar postal-code hydration with `#[AsPostalCode(country: ...)]`.

```
composer require cline/semver
```

Install `cline/semver` when you want first-class `Version` and `Constraint`DTO properties for semantic version payloads.

Struct also ships built-in deterministic string transformation attributes such as `#[Trim]`, `#[SnakeCase]`, `#[Slug]`, `#[Limit]`, `#[Replace]`, and extraction attributes like `#[After]`, `#[Before]`, and `#[Between]`. It also ships missing-value generators such as `#[Uuid]`, `#[Ulid]`, `#[Random]`, and `#[Password]` for DTO fields that should be created only when the input key is absent. Install `ramsey/uuid` if you want to use `#[Uuid(...)]`. String transforms and generators now live under `Cline\Struct\Attributes\Strings`, while compatibility aliases remain available at `Cline\Struct\Attributes`. Collection transforms now live under `Cline\Struct\Attributes\Collections`, including helpers such as `#[Collections\\Reverse]`, `#[Collections\\Unique]`, `#[Collections\\Slice]`, and `#[Collections\\OnlyKeys]`. Struct also ships first-class detached `Illuminate\\Support\\Collection` property support through `#[AsCollection(...)]`, separate from `DataList` and `DataCollection`, including callback-based collection attributes such as `#[Collections\\Filter(...)]`, `#[Collections\\Map(...)]`, `#[Collections\\GroupBy(...)]`, `#[Collections\\UniqueBy(...)]`, and `#[Collections\\MapInto(...)]`. Collection-returning transforms also include attributes such as `#[Collections\\Where(...)]`, `#[Collections\\Pluck(...)]`, `#[Collections\\Flatten(...)]`, `#[Collections\\ChunkWhile(...)]`, `#[Collections\\MapToGroups(...)]`, `#[Collections\\CountBy(...)]`, `#[Collections\\Diff(...)]`, `#[Collections\\Merge(...)]`, `#[Collections\\Pipe(...)]`, `#[Collections\\Tap(...)]`, and conditional wrappers like `#[Collections\\When(...)]`. Derived collection results and generated collection sources live under `Cline\\Struct\\Attributes\\CollectionResults` and `Cline\\Struct\\Attributes\\CollectionSources`, for methods such as `#[Contains('posts', ...)]`, `#[After('posts', ...)]`, `#[ToJson('posts')]`, `#[Reduce('totals', ...)]`, `#[Wrap(source: 'name')]`, and `#[FromJson(source: 'payload')]`. For deferred traversal, Struct also ships `LazyDataList` and `LazyDataCollection` with explicit `#[AsLazyDataList(...)]` and `#[AsLazyDataCollection(...)]` attributes. These lazy wrappers keep Struct-owned collection semantics and typed item hydration, but they are transport-focused and intentionally reject `Attributes\\Collections\\*`transforms in v1. Struct also now supports detached `Illuminate\\Support\\LazyCollection` DTO properties through `#[AsLazyCollection(...)]`, with a strict-lazy transform subset such as `#[Collections\\Map(...)]`, `#[Collections\\Filter(...)]`, `#[Collections\\Skip(...)]`, and `#[Collections\\Take(...)]`. Derived `CollectionResults` may read from lazy sources, but eager-only collection transforms are rejected on `LazyCollection` properties.

### Context-Aware Hydration

[](#context-aware-hydration)

Hydration hooks can opt into whole-DTO context when a cast or attribute needs to inspect the raw payload or sibling values that have already been resolved.

```
use Cline\Struct\Contracts\ContextualCastInterface;
use Cline\Struct\Metadata\PropertyMetadata;
use Cline\Struct\Support\PropertyHydrationContext;

final class SlugCast implements ContextualCastInterface
{
    public function get(PropertyMetadata $property, mixed $value): mixed
    {
        return $value;
    }

    public function getWithContext(
        PropertyMetadata $property,
        mixed $value,
        PropertyHydrationContext $context,
    ): mixed {
        return ($context->resolvedProperties['mode'] ?? null) === 'strict'
            ? mb_strtolower((string) $value)
            : (string) $value;
    }

    public function set(PropertyMetadata $property, mixed $value): mixed
    {
        return $value;
    }
}
```

`PropertyHydrationContext` exposes the DTO class, current property, raw input, and the sibling properties resolved so far. The context is passed as an immutable argument during hydration; Struct does not mutate shared cast instances with request-scoped data.

Documentation
-------------

[](#documentation)

- Consumer guide: [USAGE.md](USAGE.md)
- Benchmarking workflows: [BENCHMARK.md](BENCHMARK.md)

Change log
----------

[](#change-log)

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

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please use the [GitHub security reporting form](https://github.com/faustbrian/struct/security) rather than the issue queue.

Credits
-------

[](#credits)

- [Brian Faust](https://github.com/faustbrian)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance96

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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 ~1 days

Total

10

Last Release

50d ago

Major Versions

1.x-dev → 2.0.02026-03-18

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22145591?v=4)[Brian Faust](/maintainers/faustbrian)[@faustbrian](https://github.com/faustbrian)

---

Top Contributors

[![faustbrian](https://avatars.githubusercontent.com/u/22145591?v=4)](https://github.com/faustbrian "faustbrian (63 commits)")

---

Tags

php

### Embed Badge

![Health badge](/badges/cline-struct/health.svg)

```
[![Health](https://phpackages.com/badges/cline-struct/health.svg)](https://phpackages.com/packages/cline-struct)
```

###  Alternatives

[guava/filament-knowledge-base

A filament plugin that adds a knowledge base and help to your filament panel(s).

206120.5k1](/packages/guava-filament-knowledge-base)

PHPackages © 2026

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