我不确定该怎么做。我有一个用于处理数据以匹配数据库其余部分的工作表,以及一个要将最终数据传输到的已发布表。尽管truncate()
执行并清除了Report
表,但是Prescription
表在运行后仍然为空。这是我不理解的口才问题吗?
这是我的代码:
// call working table
$reports = Report::orderBy('id', 'asc');
// loop through every working report and save as a new prescription
foreach ($reports as $report) {
$prescription = new Prescription();
$prescription->script_id = $report->script_id;
$prescription->medication = $report->medication;
$prescription->fill_date = $report->fill_date;
$prescription->type = $report->type;
$prescription->quantity = $report->quantity;
$prescription->supply = $report->supply;
$prescription->insurance = $report->insurance;
$prescription->rx_number = $report->rx_number;
$prescription->copay = $report->copay;
$prescription->tr = $report->tr;
$prescription->cogs = $report->cogs;
$prescription->fees = $report->fees;
$prescription->ncr = $report->ncr;
$prescription->save();
}
// truncate working table
$reports->truncate();
// return
$message = 'All records transferred to prescriptions table.';
return redirect('reports')->with('success', $message);
答案 0 :(得分:3)
您在报表查询中缺少->get()
,因此无法实际检索结果。实际上,$reports
仅包含查询构建器对象。
$reports = Report::orderBy('id', 'asc')->get();
您很可能随后需要调整截断调用:
Report::truncate();