Download the PHP package fab2s/laravel-dt0 without Composer

On this page you can find all versions of the php package fab2s/laravel-dt0. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-dt0

Laravel Dt0

CI QA codecov Latest Stable Version PHPStan PRs Welcome License

A powerful Laravel integration for fab2s/dt0, bringing true immutability, Laravel validation, and Eloquent model casting to your Data Transfer Objects.

Why Dt0?

Traditional DTOs with mutable properties miss the core purpose: guaranteeing that data won't be accidentally modified. Dt0 leverages PHP 8.2+'s native readonly properties to enforce immutability at the language level, not by convention, but by design.

Key Benefits:

Note: This package extends fab2s/dt0 with Laravel-specific features (validation, Eloquent casting). All features from the base package, including property casting, property renaming, default values, output filtering, and more, work seamlessly here. Visit the dt0 documentation for the complete feature set.

Flexible, not dogmatic. While immutability is the core feature, Dt0 doesn't force it. Use mutable properties when needed. Expose protected properties via with(). The package provides capabilities; you decide how to use them.

Dt0 vs spatie/laravel-data

Feature Comparison

Feature Dt0 spatie/laravel-data
True immutability (readonly) Native, enforced Optional, by convention
Laravel validation Built-in Built-in
Eloquent model casting Built-in Via package
Encrypted properties Built-in (EncryptedCaster) Manual
Bidirectional casting #[Cast(in:, out:, both:)] Separate Cast + Transformer
Property renaming #[Cast(renameFrom:, renameTo:)] #[MapInputName] / #[MapOutputName]
Dependencies 2 illuminate components Full framework service provider
PHPStan level 9 6
PHP 8.2+ readonly First-class Supported but not enforced

Performance

Benchmarks from fab2s/dt0 (reproducible via the benchmark script):

Operation Dt0 spatie/laravel-data Speedup
Simple DTO (8 props, 5 casts) 142 µs 1,158 µs ~8x faster
Complex DTO (nested + arrays) 742 µs 3,628 µs ~5x faster
toArray() (simple, cached) 3.6 µs 679 µs ~189x faster
toArray() (nested, cached) 3.6 µs 2,056 µs ~571x faster

Table of Contents

Installation

Quick Start

Real-World Example

A complete request-to-response flow with validation, Eloquent casting, and typed access:

Form Request Integration

Dt0 pairs with Form Requests for teams that prefer that pattern:

Core Features

Creating DTOs

Extend fab2s\Dt0\Laravel\Dt0 for full Laravel integration:

Factory Methods

Dt0 provides multiple ways to instantiate:

new vs Factory Methods When using `new` directly with **promoted readonly properties that have a default value**, PHP initializes them immediately, **before** Dt0 can apply casting. Promoted properties without defaults behave normally. See [Dt0 readme](https://github.com/fab2s/dt0/?tab=readme-ov-file#new-vs-factory-methods) for more details. **Best practice**: Use factory methods (`make`, `from`, `fromArray`, etc.) for full casting support. Reserve `new` for cases where you're passing already-correct types or relying on defaults.

Serialization

Immutable Updates

Create modified copies without mutating the original:

Laravel Validation

Laravel Dt0 integrates seamlessly with Laravel's validation system. Validation runs on input data before any casting or instantiation.

Note: This package uses Laravel's Validator under the hood. All Laravel validation rules, custom rule objects, and error message customization work exactly as documented in Laravel.

Defining Rules

Rules can be defined at three levels:

1. Via Validate Class Attribute

2. Via Rules Class Attribute

3. Via Rule Property Attribute

When to use each approach:

Approach Best for
Property #[Rule] Keeping rules close to properties, self-documenting DTOs
Class #[Rules] Grouping rules together, inherited properties
#[Validate] Rules Default/fallback rules that subclasses can override

Rule Priority

When the same property has rules defined at multiple levels, only the highest priority rule applies — rules are not merged.

Priority order: Property #[Rule] > Class #[Rules] > #[Validate] Rules

Triggering Validation

Custom Validation Rules

Use Laravel's custom rule classes:

Model Attribute Casting

Use DTOs directly as Eloquent model attributes with automatic JSON serialization:

Usage

Requirements

Your DTO must either:

Casters

Casters transform property values during hydration (input) and serialization (output). The #[Cast] attribute supports in:, out:, and both: parameters:

Built-in Casters

From fab2s/dt0:

Caster Description
ScalarCaster Converts to int, float, bool, or string
ArrayOfCaster Casts each array element to a type (scalar, Dt0, or enum)
DateTimeCaster Parses to DateTime/DateTimeImmutable
CarbonCaster Parses to Carbon/CarbonImmutable (requires nesbot/carbon)
DateTimeFormatCaster Formats DateTime to string
MathCaster High-precision decimals (requires fab2s/math)
Dt0Caster Explicit casting to a Dt0 class
ClassCaster Instantiates arbitrary classes

CollectionOfCaster

Laravel Dt0 adds CollectionOfCaster for strongly-typed Laravel Collections:

Supported types:

EncryptedCaster

Encrypt/decrypt property values using Laravel's encryption:

Auto-detection: On input, the caster automatically detects Laravel's encrypted payload format. Encrypted values are decrypted, while plaintext strings, arrays, and objects pass through unchanged. This allows flexible initialization from both plaintext and encrypted sources.

Custom encryption key and cipher: By default, EncryptedCaster uses your APP_KEY and app cipher. When you need different values, always use the config: prefix to reference config paths rather than hardcoding key material or cipher names in your source code. This also avoids source code changes when rotating keys or updating ciphers — just update the config:

The config values support base64:-encoded keys, just like APP_KEY:

Other options:

Performance: Encrypter instances are statically cached by key and cipher combination. Multiple DTO instances or properties using the same encryption key share a single Encrypter, avoiding repeated instantiation overhead.

Stack trace safety: All sensitive parameters (keys, plaintext values) are annotated with #[\SensitiveParameter] and redacted from exception stack traces.

Eloquent model safety: When using an EncryptedCaster DTO as an Eloquent model attribute, calling $model->toArray() or $model->toJson() will trigger the DTO's output casters, meaning encrypted fields are always encrypted in the serialized output. Plaintext is only accessible through direct property access on the DTO instance ($model->myDto->apiKey).

Artisan Generator

Scaffold new DTOs with the make:dt0 Artisan command:

The service provider is auto-discovered — no manual registration needed.

Compatibility

PHP Laravel Status
8.2 11.x, 12.x Supported
8.3 11.x, 12.x, 13.x Supported
8.4 11.x, 12.x, 13.x Supported
8.5 13.x Supported

Contributing

Contributions are welcome! Please feel free to:

License

Laravel Dt0 is open-sourced software licensed under the MIT license.


All versions of laravel-dt0 with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
fab2s/dt0 Version ^2.0.0
illuminate/translation Version ^11.0|^12.0|^13.0
illuminate/validation Version ^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fab2s/laravel-dt0 contains the following files

Loading the files please wait ...