Skip to content

SimpleDTO API

Complete API reference for SimpleDTO.

Create from array.

$dto = UserDTO::fromArray($data);

Create from JSON.

$dto = UserDTO::fromJson($json);

Create from Eloquent model.

$dto = UserDTO::fromModel($user);

Create from HTTP request.

$dto = UserDTO::fromRequest($request);

Validate and create.

$dto = UserDTO::validateAndCreate($_POST);

Validate DTO.

$dto->validate();

Check if valid.

if ($dto->isValid()) {
// ...
}

Get validation errors.

$errors = $dto->getErrors();

Convert to array.

$array = $dto->toArray();

Convert to JSON.

$json = $dto->toJson();

Convert to XML.

$xml = $dto->toXml();

Convert to Eloquent model.

$user = $dto->toModel(User::class);

Set context.

$dto = $dto->with('admin');

Include lazy properties.

$dto = $dto->include(['posts', 'comments']);

Include only specified properties.

$dto = $dto->only(['name', 'email']);

Exclude specified properties.

$dto = $dto->except(['password', 'token']);