Download the PHP package ccharz/laravel-dto-lite without Composer
On this page you can find all versions of the php package ccharz/laravel-dto-lite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-dto-lite
Laravel Data Transfer Object Lite
This is a basic implementation of the data transfer object (DTO) concept. The idea is to describe input and output of data in one simple basic php class file. It is meant to replace FormRequests and Resources and can also be used to automatically generate typescript definitions.
This package is similar to the Laravel Data Package from Spatie. The main difference it contains no reflection class magic and only provides the basic functionalities.
Installation
Usage
Example DTO
Casts
Casts for attributes can be defined similar to eloquent casts. It is also possible to define casts to an array
Validation
If a rules method exists, validation is automatically performed when creating a DTO from a request manually or by automatic dependency injection.
You can also inject the rules from casts in your rules:
Automatic Injection
With the help if laravels dependency injection, the dto can be used in a controller method function and is automatically filled with the validated input data from the request.
Eloquent Castable
DataTransferObjects can be used as a cast in eloquent models
If the column is nullable, you have to append the cast parameter "nullable":
Response
Data Transfer Objects are automatically converted to an response if returned from a controller
You can also return a resource collection of data transfer objects
Map to DTO Array
An array can automatically be mapped to an array of the DTO:
Typescript Definitions
You can use https://github.com/spatie/laravel-typescript-transformer to automatically generate typescript definitions for your Data Transfer Objects and Enums.
generates to the following typescript definition:
Artisan Command
To create a new data transfer object, use the make:dto Artisan command: