【发布时间】:2021-03-09 21:16:10
【问题描述】:
有一个控制器来保存订单,还有一些复选框输入。
我试图解释一下,如果该输入被选中......必须运行一些代码。但在任何条件模式下
$debatorprice、$payment 和 $kalaf 返回 null
public function store(Request $request)
{
if ($request['image']){
$file = $request['image'];
$imgname = $file->getClientOriginalName();
$this->ImageUploader($file, '/upload/orders/');
}else{
$imgname=null;
}
$payment="";
$debatorprice="";
if ($request->has('paymentstatus')){
$payment=1;
$debatorprice=0;
}else{
$payment=0;
$totalprice=$request->totalprice;
$beforeprice=$request->beforeprice;
$debatorprice=$totalprice-$beforeprice;
}
$kalaf='';
if ($request->has('kalaf')){
$kalaf=1;
}else{
$kalaf=0;
}
offlineorder::create([
'ProductType'=>$request->producttype,
'OtherProduct'=>$request->otherproduct,
'CustomerName'=>$request->customername,
'CorporateName'=>$request->corporatename,
'Phone'=>$request->phone,
'Width'=>$request->width,
'Height'=>$request->height,
'Model'=>$request->model,
'Material'=>$request->material,
'Color'=>$request->color,
'Count'=>$request->count,
'Kalaf'=>$request->kalaf,
'Image'=>$imgname,
'Text'=>$request->text,
'Description'=>$request->description,
'TotalPrice'=>$request->totalprice,
'BeforePrice'=>$request->beforeprice,
'PaymentStatus'=>$payment,
'DebtorPrice'=>$debatorprice,
'SKU'=>$request->sku,
'ChapStatus'=>0,
'DesignStatus'=>0,
'View'=>0,
'Link'=>0,
]);
session()->flash('add_order','سفارش شما با موفقیت ثبت شد');
return back();
}
我尝试了if ($request->paymentstatus==null),但也没有用
【问题讨论】:
-
一方面,您没有在
'Kalaf'=>$request->kalaf,中使用$kalaf。你的复选框有值吗?你dd($request)看看它们是否真的在请求中发送了吗?! -
尝试使用 isset($request->paymentstatus) 代替空条件
标签: php laravel if-statement checkbox laravel-8