如何在表的单行中保存两个数组列表?
我已经尝试遍历每个数组,但是我只想知道如何将数组保存在表的单行中,请看下面的图片。我不想有一个空值。因为此功能就像在job_orders中引用的单个文件一样。
$date = $request->get('date');
$client_name = $request->get('client_name');
$address = $request->get('address');
$service_date = $request->get('service_date');
$service_time = $request->get('service_time');
$contact_person = $request->get('contact_person');
$vehicle = $request->get('vehicles');
$services = $request->input('services');
$supplies = $request->input('supplies');
$accessories = $request->input('accessories');
$miscellaneous = $request->input('miscellaneous');
DB::begintransaction();
try{
$data = [
'vehicle_id' => $request->get('vehicle_id'),
'service_date' => $request->get('service_date'),
'service_time' => $request->get('service_time'),
'discount' => $request->get('discount'),
'total' => $request->get('total'),
'technician' => $request->get('technician'),
'assistant' => $request->get('assistant'),
];
$joborders = $this->joborders->create($data);
if($services !== null){
foreach($services as $service) {
$data = [
'job_order_id' => $joborders->id,
'service_name' => $service['service_name'],
'service_qty' => $service['service_qty'],
'service_cost' => $service['service_cost'],
];
$this->items->create($data);
}
}
if($supplies !== null ){
foreach($supplies as $supply){
$data = [
'job_order_id' => $joborders->id,
'supply_name' => $supply['supply_name'],
'supply_qty' => $supply['supply_qty'],
'supply_cost' => $supply['supply_cost'],
];
$this->items->create($data);
}
}
if($accessories !== null){
foreach($accessories as $accessory){
$data = [
'job_order_id' => $joborders->id,
'accessory_name' => $accessory['accessory_name'],
'accessory_qty' => $accessory['accessory_qty'],
'accessory_cost' => $accessory['accessory_cost'],
];
$this->items->create($data);
}
}
if($miscellaneous !== null)
{
foreach($miscellaneous as $misc){
$data = [
'job_order_id' => $joborders->id,
'misc_name' => $misc['miscellaneous_name'],
'misc_qty' => $misc['miscellaneous_qty'],
'misc_cost' => $misc['miscellaneous_cost'],
];
$this->items->create($data);
}
}