当我的视图上的单选按钮值为“new”时,我想将表单中的数据存储到数据库中的两个表中,但是发生了以下问题。但如果该值是“存在的”,它的工作正常。 我的代码有什么问题?
数组转换为字符串(SQL:插入
customers
(company_name
,address
,service_id
,tc_name
,tc_dept
,{{ 1}},tc_phone
,tc_email
,bill_name
,bill_dept
,bill_phone
,bill_email
,updated_at
)值(PT Bank) ABC,JL Sudirman,1,Budi,Technical,0812345678,budi @ abc.co.id,Joko,Finance,08123456789,joko @ abc.co.id,2016-12-14 11:21:26,2016-12- 14 11:21:26))
这是我的商店代码
created_at
if($request->select_data == 'new'){
$customer = New Customer;
$customer->company_name = $request->company_name;
$customer->address = $request->address;
$customer->service_id = $request->service_id;
$customer->tc_name = $request->tc_name;
$customer->tc_dept = $request->tc_dept;
$customer->tc_phone = $request->tc_phone;
$customer->tc_email = $request->tc_email;
$customer->bill_name = $request->bill_name;
$customer->bill_dept = $request->bill_dept;
$customer->bill_phone = $request->bill_phone;
$customer->bill_email = $request->bill_email;
$customer->save();
$salesorder = New SalesOrder;
$salesorder->pid = $request->pid;
$salesorder->project_name = $request->project_name;
$salesorder->customer_id = $request->company_id;
$salesorder->total = $request->totalfee;
$salesorder->status = 'submit';
$salesorder->detail = $request->detail;
$salesorder->save();
}else{
$salesorder = New SalesOrder;
$salesorder->pid = $request->pid;
$salesorder->project_name = $request->project_name;
$salesorder->customer_id = $request->company_id;
$salesorder->total = $request->totalfee;
$salesorder->status = 'submit';
$salesorder->detail = $request->detail;
$salesorder->save();
//dd($salesorder);
}
结果
dd($request->all());
单选按钮html代码
array:32 [▼
"sales_order_id" => "9"
"select_data" => "new"
"company_id" => "2"
"company_name" => "PT Bank ABC"
"address" => "JL Sudirman"
"tc_name" => "Budi"
"tc_dept" => "Technical"
"tc_phone" => "0812345678"
"tc_email" => "budi@abc.co.id"
"bill_name" => "Joko"
"bill_dept" => "Finance"
"bill_phone" => "08123456789"
"bill_email" => "joko@abc.co.id"
"pid" => "PID002"
"project_name" => "Implementasi"
"order_identifier" => array:2 [▶]
"service_name" => array:2 [▶]
"service_id" => array:2 [▶]
"order_type" => array:2 [▶]
"select_plan" => array:2 [▶]
"qty" => array:2 [▶]
"unit_price" => array:2 [▶]
"total_price" => array:2 [▶]
"note" => array:2 [▶]
"emp_name" => array:1 [▶]
"emp_id" => array:1 [▶]
"position" => array:1 [▶]
"position_id" => array:1 [▶]
"mandays" => array:1 [▶]
"detail" => "Coba Coba"
"totalfee" => "3100"
"_token" => "uxmXBwJKHWIoXDSFetU4oRgTiTftYEhhdpx4CaPr"
]
答案 0 :(得分:1)
尝试更改两个单选按钮的ID,不能为不同的元素设置相同的ID,它会表现不同
答案 1 :(得分:1)
Try this one
<input name="select_data" name="select_data" type="radio" value="new">
<span class="lbl">New</span>
<input name="select_data" name="select_data" type="radio" value="existing">
<span class="lbl">Existing</span>
答案 2 :(得分:1)
问题是因为某些$request
属性是数组。您无法在integer
,string
等列中存储数组。如果要将它们存储为数组,可以将它们序列化:
$customer->service_id = json_encode(service_id);
并存储在text
或json
列中:
$table->json('service_id');
$table->text('service_id');