public function saveOrder(Request $request)
{
$sid = explode(",", $request->subcat_id);
$quan = explode(",", $request->quantity);
$amnt = explode(",", $request->amount);
$c = count($sid);
for($i=0; $i < $c; $i++) {
$order = new Order();
$order->quantity = $quan[$i];
$order->amount = $amnt[$i];
$order->subcat_id = $sid[$i];
$order->address = $request->address;
$order->payment_mode = $request->payment_mode;
$order->order_no = $this->generateOrderNR();
if ($request->hasFile('image')) {
echo "in".$i;
$file = $request->file('image');
$file_name = time() . rand(1, 999) . '.' . $file->getClientOriginalExtension();
$file->move(base_path('images/orders/'), $file_name);
$order->image = $file_name;
}
if ($order->save()) {
echo "Order";
//return response()->json(['status' => 200, 'msg' => 'Order Placed Successfully']);
} else
echo "Error";
//return response()->json(['status' => 200, 'msg' => 'Error Occured']);
}
}
in0 Order in1{文件277762619_112136134785398_1736805384468006822_n.j g"由于未知错误而未上传。">
为什么这个错误每次都会出现,因为这个错误在数据库中只有1行保存,而另一行不保存,当通过api在postman中这样发送数据时:-
address: Lucknow,
quantity: 1,1,
amount: 150,162,
payment_mode: CASH,
subcat_id: 8,12
你想上传的第二个文件可能太大了。如果文件大小超过upload_max_filesize
,请检查php.ini
。然后,增加1000M
之类的大小。然后重启apache。
可以在插入或创建方法中传递数组,而不是循环。检查下面的代码示例:
AppSettings::insert([
[
'name'=>'mail_host',
'type'=>$emailsettingstype->id,
'value'=>'',
],
[
'name'=>'mail_port',
'type'=>$emailsettingstype->id,
'value'=>'',
],
[
'name'=>'mail_username',
'type'=>$emailsettingstype->id,
'value'=>'',
],
]);
用这个代替move()
$file = $request->file('image');
$file_name = time().rand(1, 999).'.'.$file->getClientOriginalExtension();
File::copy($file->getPathname(), base_path('images/orders/'.$file_name));