Carts seems to be multiple
dd($carts);
$parcel = array(
'length'=> '6',
'width'=> '5',
'height'=> '5',
'distance_unit'=> 'in',
'weight'=> $carts->weight,
'mass_unit'=> 'lb',
);
Guys, I'm brand new to the Laravel universe, and I apologize for this long message. I'm putting the finishing touches on my first ecommerce store, but I'm having issues getting the shipping api to function so I can charge the customer for shipping rates. I decided to go to with Shippo for the api because I heard it was compatible with Laravel, but it is difficult. I managed to get the code to read the customer's submitted address dynamically, but I can't seem to do the same for the weight, thus the error
Property [weight] does not exist on this collection instance.
I'm using the
use Gloudemans\Shoppingcart\Facades\Cart;
$carts = Cart::content();
to read the cart data on the payment page and it works. When I do a die dump with $carts, I can read the content data, but when I try to execute the following code like so
$parcel = array(
'length'=> '6',
'width'=> '5',
'height'=> '5',
'distance_unit'=> 'in',
'weight'=> $carts->weight,
'mass_unit'=> 'lb',
);
I get the Property[weight] error. Does anybody know how to solve this issue?
@newlaravelcoder https://laravel.com/docs/8.x/collections#method-sum
You can sum the members of the carts collection;
'weight'=> $carts->sum('weight'),
Please or to participate in this conversation.