class OrderData extends Data
{
public function __construct(
/** @var ProductData[] */
public array $products,
)
{
}
}
class ProductData extends Data
{
public function __construct(public Product $product, public int $quantity)
{
}
}
"errors": {
"products.4": "The products.4 field must be an array.",
"products.511": "The products.511 field must be an array."
}
$list = $this->request->input('propertyList', []);
$model->property()->detach(array_keys($list));
foreach ($list as $propertyId => $row) {
foreach ($row as $key => $value) {
if (is_array($value)) {
foreach ($value as $item) {
$model->property()->attach([$propertyId => [$key => $item]]);
}
} else {
$model->property()->attach([$propertyId => [$key => $value]]);
}
}
}