Two Laravel devs that won't disappear on you. Finally! Hire Joel and Aaron from No Compromises.

Laravel Data

spatie/laravel-data image

Laravel Data stats

Downloads
2.9M
Stars
900
Open Issues
7
Forks
139

View on GitHub →

Create unified resources and data transfer objects

Laravel Data Package by Spatie

The Laravel Data package by Spatie simplifies data handling in Laravel applications by allowing developers to use rich data objects across various contexts. This tool is designed to reduce redundancy and improve data consistency by centralizing data definitions and functionality.

Key Features

  • Unified Data Objects: Replace form requests, API transformers, and TypeScript definitions with versatile data objects.
  • Automatic Transformations: Data objects can automatically convert into Laravel API resources or other desired formats.
  • Lazy Properties: Optimize performance by transforming only requested data properties.
  • Validation Integration: Automatically generate and resolve validation rules from data object properties.
  • TypeScript Support: Generate TypeScript definitions directly from your PHP data objects, ensuring consistency across the front and back end.
  • Eloquent Model Compatibility: Data objects can be directly saved as properties of Eloquent models.

Benefits

  • Type Safety: Ensures data types are consistent across your application, reducing errors.
  • Reduced Redundancy: Eliminate the need to declare properties multiple times in different layers of your application.
  • Simplified Validation: Leverage PHP's type system to reduce the amount of explicit validation rules needed.

Installation and Usage

Install the package via composer:

composer require spatie/laravel-data

To implement, extend the Data class in your data objects:

use Spatie\LaravelData\Data;
 
class SongData extends Data
{
public function __construct(
public string $title,
public string $artist,
) {
}
}

Learning Resources

Additional Information

  • Documentation: Comprehensive documentation is available here.
  • Support: Contributions to the package are welcomed, and support for the creators can be shown through Spatie’s paid products.

This package is open-sourced under the MIT license and continues to be developed and maintained by Spatie with contributions from the community.

For developers looking to streamline data management in their Laravel applications, the Laravel Data package offers a robust, efficient, and unified approach.

spatie photo

We create open source, digital products and courses for the developer community

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Spatie Laravel Data Related Articles

Spatie Shares Their Coding Guidelines as AI Skills image

Spatie Shares Their Coding Guidelines as AI Skills

Read article
Log User Activity in Your Laravel App with Activity Log v5  image

Log User Activity in Your Laravel App with Activity Log v5

Read article
Nimbus: An In-Browser API Testing Playground for Laravel image

Nimbus: An In-Browser API Testing Playground for Laravel

Read article
Memoization and Function Caching with this PHP Package image

Memoization and Function Caching with this PHP Package

Read article
Packistry is a Self-hosted Composer Repository Made with Laravel image

Packistry is a Self-hosted Composer Repository Made with Laravel

Read article
Laravel Backup Server v4 Released as Open Source image

Laravel Backup Server v4 Released as Open Source

Read article
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm