New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

agelxnash/laravel-magic-dto

6 4
Install
composer require agelxnash/laravel-magic-dto
Latest Version:1.0.1
PHP:^8.0
Laravel:9 · 10 · 11
License:MIT
Last Updated:Feb 25, 2024
Links: GitHub  ·  Packagist
Maintainer: Agel Nash

Magic DTO

Total Downloads codecov

class ExampleDto extends MagicDto
{
    public function __construct(
        public int $propInt,
        public float $propFloat,
        public CarbonImmutable $date,
        public ?ExampleDto $nested = null,
    ) {
    }
}
ExampleDto::from([
    'propInt' => 666,
    'propFloat' => '100.5',
    'date' => '2023-12-11',
    'nested' => [
        'date' => '2024-02-23',
        'propInt' => 777,
        'propFloat' => '200.1',
    ],
])
// or
ExampleDto::from([
    'prop_int' => 666,
    'prop_float' => '100.5',
    'date' => '2023-12-11',
    'nested' => [
        'date' => '2024-02-23',
        'prop_int' => 777,
        'prop_float' => '200.1',
    ],
])
Inject eloquent models

composer require "illuminate/database" required when you need to use AgelxNash\MagicDto\Attributes\InjectModel

Class User extends Illuminate\Database\Eloquent\Model {}

class ExampleDto extends MagicDto
{
    public function __construct(
        #[InjectModel(User::class, 'id')]
        public User $user1,
        #[InjectModel(User::class, 'email')]
        public User $user2,
    ) {
    }
}

ExampleDto::from(['user1' => 777]);
ExampleDto::from(['user2' => 'agel-nash@example.com']);

Author


Borisov Evgeniy
Agel_Nash

Laravel, MODX, Security Audit



https://agel-nash.ru
Telegram: @agel_nash
Email: laravel@agel-nash.ru
Donation


ЮMoney: 41001299480137

Related Packages

jcrowe/type-safe-collection

A thin wrapper around Illuminate/Collection that allows for enforcing type const...

9,236 4
altra/dto

Package to create dto

11,452 0
ccharz/laravel-dto-lite

Simple Laravel Data Transfer Object

2,681 0
bpartner/dto

DTO with simple factory

1,429 0
spatie/array-to-xml

Convert an array to xml

77,815,895 1,199

Version History

Version Released PHP Laravel License
1.0.1 ^8.0 ^9|^10|^11 MIT
1.0.0 ^8.0 ^9|^10|^11 MIT