**trying to pass the data in database into variable and then insert to another table**
$ query = DB :: table('students')-> where('studno',$ request-> input('stud_id'))-> get();
如何?
我想将该行复制到另一个表中,并在其中添加时间
答案 0 :(得分:0)
尝试此代码。效果很好,但是您必须指定所有剩余的列
$students = DB::table('students')->where('studno', $request->input('stud_id'))->get();
$data = [];
foreach ($students as $student) {
$singleData['studno'] = $student->studno;
$singleData['batch'] = $student->batch;
......
// other column specify yourself
$data[] = $singleData;
}
if ($data) {
$isSavedAttendances = DB::table('attendances')->insert($data);
// $isSavedAttendances must be true or false
}