34 lines
734 B
PHP
34 lines
734 B
PHP
<?php
|
|
|
|
namespace App\Data\Cart;
|
|
|
|
use App\Contracts\InputDataTransferObject;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
final readonly class AddToCartDTO implements InputDataTransferObject
|
|
{
|
|
public function __construct(
|
|
public int $productId,
|
|
public int $quantity
|
|
) {}
|
|
|
|
public static function fromRequest(FormRequest $request): InputDataTransferObject
|
|
{
|
|
return new self(
|
|
productId: $request->productId,
|
|
quantity: $request->quantity
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'productId' => $this->productId,
|
|
'quantity' => $this->quantity,
|
|
];
|
|
}
|
|
}
|