Download the PHP package kfoobar/laravel-dto without Composer

On this page you can find all versions of the php package kfoobar/laravel-dto. 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-dto

Basic Data Transfer Object for Laravel

A small DTO base class for populating declared public properties from arrays, Laravel requests and Eloquent models.

This branch prepares 2.0.0, an unreleased major version. See CHANGELOG.md for breaking changes.

Requirements

Laravel PHP Testbench (development)
12 8.2–8.5 10
13 8.3–8.5 11

The package requires PHP ^8.2, Illuminate Database and HTTP ^12.0 || ^13.0, and Carbon ^3.8.4. CI covers the PHP versions listed above.

Installation

Once version 2 is released:

No service provider or configuration is needed. To work with this unreleased checkout, run composer install in the repository.

Usage

All factories return the concrete DTO subclass:

fromRequest() uses $request->all(). It does not validate or limit input to validated fields. With a Form Request, use:

fromModel() uses $model->toArray(), including Eloquent casts, visible/appended attributes and already loaded relationships. Hidden attributes stay excluded. Nested arrays are not automatically converted into other DTOs.

For a JSON response, use response()->json($postData).

Missing values and null

Only keys present in the input are assigned. Unknown keys, static properties and non-public properties are ignored.

Declare a default when a field should always be readable:

Type conversion

For a single named type, int, float, string, bool, array and object use PHP's corresponding explicit cast. Nullable named types use the same conversion for non-null input. In particular, array now correctly converts a scalar to a one-element array.

Casts are not validation: (bool) 'false' is true, (bool) '0' is false, and (int) 'invalid' is 0. Validate request data before constructing the DTO when these conversions are inappropriate.

Union types use PHP's native coercive property-assignment rules, preserving an already matching type:

Incompatible values raise TypeError. Unions do not apply the package's single-type array/object casts or Carbon parsing. For example, Carbon|string retains a string, while Carbon|CarbonImmutable requires an instance of one of those classes. Intersection and DNF types also use PHP's native assignment checks.

Other class and interface types require compatible objects; the package does not instantiate arbitrary classes. Inherited public properties and uninitialized public readonly properties are supported.

Conversions run during construction and factory calls. Later direct assignments to public properties follow PHP's normal rules and do not run DTO conversions.

Carbon dates

Declare Carbon\Carbon, Carbon\CarbonImmutable, or a subclass such as Illuminate\Support\Carbon to enable date conversion. Nullable declarations such as ?CarbonImmutable are supported.

Use an instance for properties typed as CarbonInterface or as a union of date classes.

Upgrading from 1.x

  1. Upgrade to PHP 8.2+ and Laravel 12, or PHP 8.3+ and Laravel 13. Carbon 2 is no longer supported.
  2. Import KFoobar\Data\DataTransferObject. The previous README's KFoobar\LaravelData\Objects\DataTransferObject namespace was incorrect.
  3. Remove new before static factory calls: use PostData::fromArray(...).
  4. Add explicit defaults to fields that must remain readable when omitted. Missing typed properties no longer receive an implicit null, and defaults are preserved.
  5. Review code relying on the broken untyped/array behavior or magic access to protected/private properties. Magic access now respects the public instance-property boundary; unknown writes are still ignored and unknown reads return null.
  6. Update overridden methods to match the base signatures. Factories return static; setPropertyType() now accepts ?ReflectionType and mixed, and returns mixed.

Development

The PHPUnit 11 / Orchestra Testbench suite covers hydration, defaults, nullability, scalar casts, unions, other PHP property types, Carbon, requests, Form Request validation and persisted Eloquent models. Integration tests use an isolated SQLite :memory: database.

To resolve a specific Laravel version locally:

Use Laravel ^13.0 with Testbench ^11.0 on PHP 8.3+ for the other supported major. GitHub Actions resolves dependencies and runs the full suite across all seven supported PHP/Laravel combinations. The library's composer.lock is intentionally not committed.

License

The MIT License (MIT). See LICENSE.


All versions of laravel-dto with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^12.0 || ^13.0
illuminate/http Version ^12.0 || ^13.0
nesbot/carbon Version ^3.8.4
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 kfoobar/laravel-dto contains the following files

Loading the files please wait ...