@webrobert On my ecommerce checkout page, I'm trying to show the customer shipping rates. Shippo needs to know their address information which is coming from this array
$to_address = array(
'name' => '',
'company' => '',
'street1' => '',
'city' => '',
'state' => '',
'zip' => '',
'country' => '',
'phone' => '',
'email' => '',
);
because the information is dynamic and the fields are attached to the UserAddress model, i changed it to this
$to_address = UserAddress::all()
->map(fn ($address) => [
'name' => $address->name,
'company' => $address->company,
'shipping_last_name' => $address->shipping_last_name,
'street1' => $address->street1,
'street2' => $address->street2,
'city' => $address->city,
'state' => $address->state,
'zip' => $address->zip,
'country' => $address->country,
'phone' => $address->phone,
'email' => $address->email,
// other fields here
])->toArray();
Likewise the $parcel array needs to find the product information from the Product Model, so I updates that to this...
$parcel = Product::all()
->map(fn ($product) => [
'length'=> $product->length,
'width'=> $product->width,
'height'=> $product->height,
'distance_unit'=> 'in',
'weight'=> $product->weight,
'mass_unit'=> 'lb',
])->toArray();
this produced an error because in the Shippo_Shipment::create array... it was expected this field
'parcels'=> array($parcel),
Which was modified like I wrote above. This appears to be the crux of the problem.