PHPackages                             spatie/laravel-data - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/laravel-data

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/laravel-data
===================

Create unified resources and data transfer objects

4.20.1(2mo ago)1.8k28.9M—1.9%281[2 issues](https://github.com/spatie/laravel-data/issues)[1 PRs](https://github.com/spatie/laravel-data/pulls)20MITPHPPHP ^8.1CI passing

Since Jun 30Pushed 1w ago7 watchersCompare

[ Source](https://github.com/spatie/laravel-data)[ Packagist](https://packagist.org/packages/spatie/laravel-data)[ Docs](https://github.com/spatie/laravel-data)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-data/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (40)Versions (142)Used By (20)

 [   ![Logo for laravel-data](https://camo.githubusercontent.com/bada5ca0eee37aaa46fd7ca7a10c8c9441b86b6a93d2a7bc28d2447aa761faa2/68747470733a2f2f7370617469652e62652f7061636b616765732f6865616465722f6c61726176656c2d646174612f68746d6c2f6c696768742e77656270)  ](https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-data)Powerful data objects for Laravel
=================================

[](#powerful-data-objects-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/04708cf608a34e47ac9147191b5abdf2d7ca652b0f5005a7455e99755b7d89a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-data)[![Tests](https://github.com/spatie/laravel-data/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-data/actions/workflows/run-tests.yml)[![PHPStan](https://github.com/spatie/laravel-data/actions/workflows/phpstan.yml/badge.svg)](https://github.com/spatie/laravel-data/actions/workflows/phpstan.yml)[![Check & fix styling](https://github.com/spatie/laravel-data/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/spatie/laravel-data/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/3cbd97b845d0cd41ecaf5a0cf1f1756c11f0e16288aa03e6f7c2b500c780b8bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-data)

This package enables the creation of rich data objects which can be used in various ways. Using this package you only need to describe your data once:

- instead of a form request, you can use a data object
- instead of an API transformer, you can use a data object
- instead of manually writing a typescript definition, you can use... 🥁 a data object

A `laravel-data` specific object is just a regular PHP object that extends from `Data`:

```
use Spatie\LaravelData\Data;

class SongData extends Data
{
    public function __construct(
        public string $title,
        public string $artist,
    ) {
    }
}
```

By extending from `Data` you enable a lot of new functionality like:

- Automatically transforming data objects into resources (like the Laravel API resources)
- Transform only the requested parts of data objects with lazy properties
- Automatically creating data objects from request data and validating them
- Automatically resolve validation rules for properties within a data object
- Make it possible to construct a data object from any type you want
- Add support for automatically validating data objects when creating them
- Generate TypeScript definitions from your data objects you can use on the frontend
- Save data objects as properties of an Eloquent model
- And a lot more ...

Why would you be using this package?

- You can be sure that data is typed when it leaves your app and comes back again from the frontend which makes a lot less errors
- You don't have to write the same properties three times (in a resource, in a data transfer object and in request validation)
- You need to write a lot less of validation rules because they are obvious through PHP's type system
- You get TypeScript versions of the data objects for free

Are you a visual learner?
-------------------------

[](#are-you-a-visual-learner)

In this talk, given at Laracon, you'll see [an introduction to Laravel Data](https://www.youtube.com/watch?v=CrO_7Df1cBc).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/db4182c9f754c4512017c316b58e9d5f00206e00eab9324e793913f3f63bb50d/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d646174612e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-data)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-data
```

Read the installation notes on the docs site: [https://spatie.be/docs/laravel-data/v4/installation-setup](https://spatie.be/docs/laravel-data/v4/installation-setup/).

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

[](#documentation)

You will find full documentation on the dedicated [documentation](https://spatie.be/docs/laravel-data/v4/introduction) site.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Ruben Van Assche](https://github.com/rubenvanassche)
- [Aidan Casey](https://github.com/aidan-casey) (Validation Attributes)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

78

—

ExcellentBetter than 100% of packages

Maintenance93

Actively maintained with recent releases

Popularity77

Solid adoption and visibility

Community54

Growing community involvement

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 71% 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 ~12 days

Recently: every ~38 days

Total

135

Last Release

62d ago

Major Versions

1.5.2 → 3.6.02023-06-02

v1.x-dev → 3.10.02023-12-01

3.11.0 → 4.0.02024-02-09

3.11.2 → 4.2.02024-03-01

v3.x-dev → 4.6.02024-05-03

PHP version history (2 changes)0.0.1PHP ^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (1452 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (103 commits)")[![alexmanase](https://avatars.githubusercontent.com/u/10696975?v=4)](https://github.com/alexmanase "alexmanase (70 commits)")[![bentleyo](https://avatars.githubusercontent.com/u/1701266?v=4)](https://github.com/bentleyo "bentleyo (44 commits)")[![Mohammad-Alavi](https://avatars.githubusercontent.com/u/24431504?v=4)](https://github.com/Mohammad-Alavi "Mohammad-Alavi (35 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (27 commits)")[![innocenzi](https://avatars.githubusercontent.com/u/16060559?v=4)](https://github.com/innocenzi "innocenzi (26 commits)")[![ragulka](https://avatars.githubusercontent.com/u/593267?v=4)](https://github.com/ragulka "ragulka (26 commits)")[![clementbirkle](https://avatars.githubusercontent.com/u/9021081?v=4)](https://github.com/clementbirkle "clementbirkle (19 commits)")[![rust17](https://avatars.githubusercontent.com/u/16575052?v=4)](https://github.com/rust17 "rust17 (19 commits)")[![CWAscend](https://avatars.githubusercontent.com/u/134165900?v=4)](https://github.com/CWAscend "CWAscend (18 commits)")[![Klaas058](https://avatars.githubusercontent.com/u/16153346?v=4)](https://github.com/Klaas058 "Klaas058 (17 commits)")[![SanderSander](https://avatars.githubusercontent.com/u/6603255?v=4)](https://github.com/SanderSander "SanderSander (16 commits)")[![Tofandel](https://avatars.githubusercontent.com/u/6115458?v=4)](https://github.com/Tofandel "Tofandel (16 commits)")[![xHeaven](https://avatars.githubusercontent.com/u/14284867?v=4)](https://github.com/xHeaven "xHeaven (13 commits)")[![erikgaal](https://avatars.githubusercontent.com/u/1234268?v=4)](https://github.com/erikgaal "erikgaal (13 commits)")[![abenerd](https://avatars.githubusercontent.com/u/7523903?v=4)](https://github.com/abenerd "abenerd (12 commits)")[![andrey-helldar](https://avatars.githubusercontent.com/u/10347617?v=4)](https://github.com/andrey-helldar "andrey-helldar (12 commits)")[![morrislaptop](https://avatars.githubusercontent.com/u/67807?v=4)](https://github.com/morrislaptop "morrislaptop (11 commits)")[![shuvroroy](https://avatars.githubusercontent.com/u/21066418?v=4)](https://github.com/shuvroroy "shuvroroy (11 commits)")

---

Tags

laravelphpspatielaravellaravel-data

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/spatie-laravel-data/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-data/health.svg)](https://phpackages.com/packages/spatie-laravel-data)
```

###  Alternatives

[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[spatie/laravel-support-bubble

A non-intrusive support chat bubble that can be displayed on any page

391173.6k](/packages/spatie-laravel-support-bubble)[spatie/laravel-rdap

Perform RDAP queries in a Laravel app

72108.3k2](/packages/spatie-laravel-rdap)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[spatie/laravel-screenshot

Take screenshots of web pages in Laravel apps

7615.9k2](/packages/spatie-laravel-screenshot)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)

PHPackages © 2026

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