我的控制器中有 store 方法,它返回以下错误:
错误
安慰Preview tab
exception: "ErrorException"
file: "C:\........\vendor\laravel\framework\src\Illuminate\Support\Str.php"
line: 419
message: "Array to string conversion"
安慰Response tab
{
"file": "C:\\........\\app\\Http\\Controllers\\Api\\Front\\CartController.php",
"line": 380,
"function": "save",
"class": "Illuminate\\Database\\Eloquent\\Model",
"type": "->"
},
代码
public function checkout(Request $request)
{
$user = auth('api')->user();
$cartItems = CartStorage::where('user_id', $user->id)->get();
$address = AddressUser::where('id', $request->input('address'))->first();
foreach($cartItems as $item) {
$cartData = $item->cart_data;
// add to orders table
try {
$order = new Order();
$order->ordernu = 'Si-'.mt_rand(1000000000, 9999999999);
$order->user_id = $user->id;
$order->order_data = $cartData;
$order->quantity = $cartData['quantity'];
$order->price = $request->input('totalPrice');
$order->courier = $request->input('courier');
$order->courier_service = $request->input('courierService');
$order->shippingcode = $request->input('shippingcode');
$order->shipping_price = $request->input('shippingPrice');
$order->address = $address->address;
$order->kecamatan = $address->kecamatan;
$order->kelurahan = $address->kelurahan;
$order->kota = $address->kota;
$order->provinsi = $address->provinsi;
$order->postalcode = $address->postalcode;
$order->weight = $request->input('weight');
$order->phone = $request->input('phone');
$order->buyer_name = $user->name;
$order->buyer_email = $user->email;
$order->note = $request->input('note');
$order->received = false;
$order->save();
}
}
}
注意:我已经测试了dd放入order列中的每一个数据,并且所有数据都获得了真实值。
任何想法?
梵蒂冈之花
忽然笑
慕虎7371278