agelxnash / laravel-magic-dto
Fund package maintenance!
yoomoney.ru/to/41001299480137
1.0.1
2024-02-25 11:52 UTC
Requires
- php: ^8.0
- illuminate/container: ^9|^10|^11
- illuminate/support: ^9|^10|^11
Requires (Dev)
- ext-pdo: *
- ext-pdo_sqlite: *
- orchestra/testbench-dusk: ^5|^6|^7|^8|^9
- phpunit/phpunit: ^8.5.30|^9.0
Suggests
- illuminate/database: If you want autowiring Eloquent models via \AgelxNash\MagicDto\Attributes\InjectModel
This package is auto-updated.
Last update: 2024-11-25 13:35:20 UTC
README
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']);